Skeleton
Skeleton is a placeholder to show a loading state and the expected shape of a component.
Import
import { Skeleton } from '@heroui/react';
Usage
"use client";
import {Skeleton} from "@heroui/react";
export function Basic() {
return (
<div className="bg-surface-1 shadow-border w-[250px] space-y-5 rounded-lg p-4">
<Skeleton className="h-32 rounded-lg" />
<div className="space-y-3">
<Skeleton className="h-3 w-3/5 rounded-lg" />
<Skeleton className="h-3 w-4/5 rounded-lg" />
<Skeleton className="h-3 w-2/5 rounded-lg" />
</div>
</div>
);
}
Text Content
"use client";
import {Skeleton} from "@heroui/react";
export function TextContent() {
return (
<div className="w-full max-w-md space-y-3">
<Skeleton className="h-4 w-full rounded" />
<Skeleton className="h-4 w-5/6 rounded" />
<Skeleton className="h-4 w-4/6 rounded" />
<Skeleton className="h-4 w-full rounded" />
<Skeleton className="h-4 w-3/6 rounded" />
</div>
);
}
User Profile
"use client";
import {Skeleton} from "@heroui/react";
export function UserProfile() {
return (
<div className="flex items-center gap-3">
<Skeleton className="h-10 w-10 shrink-0 rounded-full" />
<div className="flex-1 space-y-2">
<Skeleton className="h-3 w-36 rounded-lg" />
<Skeleton className="h-3 w-24 rounded-lg" />
</div>
</div>
);
}
List Items
"use client";
import {Skeleton} from "@heroui/react";
export function List() {
return (
<div className="w-full max-w-sm space-y-4">
{Array.from({length: 3}).map((_, index) => (
<div key={index} className="flex items-center gap-3">
<Skeleton className="h-10 w-10 shrink-0 rounded-lg" />
<div className="flex-1 space-y-2">
<Skeleton className="h-3 w-full rounded" />
<Skeleton className="h-3 w-4/5 rounded" />
</div>
</div>
))}
</div>
);
}
Styling
Passing Tailwind CSS classes
import { Skeleton } from '@heroui/react';
function CustomSkeleton() {
return (
<Skeleton className="h-20 w-32 rounded-full" />
);
}
Customizing the component classes
To customize the Skeleton component classes, you can use the @layer components
directive.
Learn more.
@layer components {
.skeleton {
@apply bg-gray-200;
}
.skeleton:before {
@apply via-gray-100;
}
}
HeroUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.
CSS Classes
The Skeleton component uses these CSS classes (View source styles):
Base Class
.skeleton
- Base skeleton styles with shimmer animation
Animation
The shimmer effect is created using a CSS gradient animation that moves across the skeleton element:
.skeleton {
@apply bg-surface-3 pointer-events-none relative overflow-hidden rounded-md;
&:before {
@apply animate-skeleton via-surface-2 absolute inset-0 -translate-x-full bg-gradient-to-r from-transparent to-transparent content-[''];
}
}
@theme inline {
--animate-skeleton: skeleton 2s linear infinite;
@keyframes skeleton {
100% {
transform: translateX(200%);
}
}
}
API Reference
Skeleton Props
Prop | Type | Default | Description |
---|---|---|---|
className | string | - | Additional CSS classes |
children | ReactNode | - | Optional child content |