Skeleton
A placeholder component used to indicate loading content while preserving layout structure. It supports multiple sizes, shimmer animation, shape variants, and composable helpers for common UI patterns.
tsx
import { Skeleton } from '@nofinite/nui';Interactive Preview
Usage
Basic usage
tsx
import { Skeleton } from '@nofinite/nui';
<Skeleton />;Custom width and height
tsx
<Skeleton width={200} height={20} />Circle skeleton
tsx
<Skeleton circle width={48} />Disable animation
tsx
<Skeleton animated={false} />Helper Components
Text
tsx
<Skeleton.Text width="60%" />Paragraph
tsx
<Skeleton.Paragraph lines={3} />Avatar
tsx
<Skeleton.Avatar size={40} />Button
tsx
<Skeleton.Button width={120} height={40} />Card
tsx
<Skeleton.Card />Variants
Size variants
tsx
<Skeleton size="xs" />
<Skeleton size="sm" />
<Skeleton size="md" />
<Skeleton size="lg" />
<Skeleton size="xl" />Available variants
- xs
- sm
- md
- lg
- xl
Guidelines
- xs/sm → dense UI or metadata lines
- md → default text placeholders
- lg/xl → headings or large elements
States
- Animated shimmer
- Static (animation disabled)
- Circle shape
- Explicit size override
- Dark mode
- Reduced motion (respects OS preference)
Accessibility
- Uses
role="presentation" - Hidden from assistive technologies by default (
aria-hidden) - Respects
prefers-reduced-motion - Prevents pointer interaction
- Preserves layout to avoid CLS (Cumulative Layout Shift)
Best Practices
Do
- Match skeleton layout with real content
- Disable animation for long-loading screens if performance sensitive
- Use circle skeleton for avatars and icons
- Use paragraph helper for text-heavy layouts
- Combine helpers to mirror complex UI
Don’t
- Use skeleton for extremely short loading durations
- Animate excessively in data-dense views
- Display skeleton after content is partially loaded
- Replace error states with skeleton
- Use mismatched skeleton sizes causing layout shift
API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
size | enum | md | The predefined height mapping for the skeleton |
width | string | number | — | Explicit width override (supports numbers as px, or strings like '100%') |
height | string | number | — | Explicit height override (supports numbers as px, or strings like '50px') |
animated | boolean | true | Enables or disables the sweeping shimmer animation. Defaults to true. |
circle | boolean | false | Forces the skeleton into a perfect circle, ignoring the size height |
ariaHidden | boolean | true | Hides the element from screen readers. Defaults to true (recommended). |