Skeleton
A skeleton loading component
Skeleton is a lightweight loading placeholder for web interfaces. It supports text, circular, and rectangular shapes and three animation modes.
The component is presentation-only: it does not manage loading state. Render it conditionally while the real content is being fetched or prepared.
Installation
CLI
npx shadcn add https://ui.tiesen.id.vn/r/skeleton.jsonManual
Copy and paste the following code into your project.
import type { VariantProps } from 'class-variance-authority'import { cva } from 'class-variance-authority'import { cn } from '@/lib/utils'const skeletonVariants = cva( "relative block overflow-hidden rounded-sm before:inline-block before:content-['\\a0']", { variants: { variant: { text: 'h-auto w-full', circular: 'aspect-square rounded-full', rectangular: '', }, animation: { pulse: 'animate-pulse bg-current', shimmer: 'animate-[shimmer_2s_cubic-bezier(0.4,0,0.6,1)_infinite] bg-[linear-gradient(110deg,var(--color-secondary),35%,var(--color-border),50%,var(--color-secondary))] bg-size-[200%_100%] dark:bg-[linear-gradient(110deg,var(--color-secondary),35%,var(--color-input),50%,var(--color-secondary))]', solid: 'bg-muted', }, }, })interface SkeletonProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof skeletonVariants> {}function Skeleton({ variant = 'rectangular', animation = 'shimmer', className, ...props}: SkeletonProps) { const Comp = { text: 'span', circular: 'div', rectangular: 'div', }[variant ?? 'rectangular'] as React.ElementType return ( <Comp data-slot='skeleton' className={cn(skeletonVariants({ variant, animation }), className)} {...props} /> )}export { Skeleton }Usage
import { Skeleton } from '@/components/ui/skeleton'
export function ProfileSkeleton() {
return (
<div className='flex items-center gap-3'>
<Skeleton variant='circular' className='size-10' />
<div className='flex-1 space-y-2'>
<Skeleton variant='text' className='max-w-48' />
<Skeleton variant='text' className='max-w-32' />
</div>
</div>
)
}Variants
rectangular
The default shape for arbitrary blocks.
<Skeleton variant='rectangular' className='h-32 w-full' />circular
Keeps a square aspect ratio and uses a fully rounded shape.
<Skeleton variant='circular' className='size-12' />text
Uses a text-like inline element and stretches to the available width.
<Skeleton variant='text' className='max-w-sm' />Animation
The default animation is shimmer.
<Skeleton animation='shimmer' />
<Skeleton animation='pulse' />
<Skeleton animation='solid' />Use solid when motion should be avoided.
API Reference
Skeleton
| Prop | Type | Default |
|---|---|---|
variant | 'text' | 'circular' | 'rectangular' | 'rectangular' |
animation | 'pulse' | 'shimmer' | 'solid' | 'shimmer' |
className | string | — |
...props | React.HTMLAttributes<HTMLDivElement> | — |
The rendered element is a span for text and a div for circular and rectangular variants.