Skeleton
Provide a placeholder while you wait for content to load, or to visualize content that doesn't exist yet.
When To Use
- When a component needs to wait for asynchronous data.
- When a component needs a placeholder to prevent content from jumping.
Data Attributes (Global Skeletons)
The easiest way to show loading states is using the global `data-skeleton="true"` attribute on any element.
astro
<!-- Add data-skeleton="true" to any element to make it a skeleton -->
<div class="flex items-center space-x-4 w-full">
<div data-skeleton="true" data-skeleton-variant="circular" class="h-12 w-12 rounded-full bg-zinc-100 dark:bg-zinc-800">
<!-- Content hidden while loading -->
</div>
<div class="space-y-2 flex-1">
<div data-skeleton="true" data-skeleton-variant="text" class="h-4 w-3/4 rounded bg-zinc-100 dark:bg-zinc-800"></div>
<div data-skeleton="true" data-skeleton-variant="text" class="h-4 w-1/2 rounded bg-zinc-100 dark:bg-zinc-800"></div>
</div>
</div> Component Usage
You can also import and use the `Skeleton` component directly.
astro
---
import Skeleton from '@/components/feedback/Skeleton.astro';
---
<div class="flex items-center space-x-4">
<Skeleton variant="circular" width={48} height={48} />
<div class="space-y-2">
<Skeleton variant="text" width={200} height={16} />
<Skeleton variant="text" width={160} height={16} />
</div>
</div> Data Attribute Variants
Customize the global attribute approach with variants: `text`, `circular`, and `rectangular`.
Text (Default)
Circular
Rectangular
astro
<!-- Text (Default) -->
<div data-skeleton="true" data-skeleton-variant="text" class="h-5 w-full bg-zinc-100 dark:bg-zinc-800 rounded"></div>
<!-- Circular -->
<div data-skeleton="true" data-skeleton-variant="circular" class="h-16 w-16 bg-zinc-100 dark:bg-zinc-800 rounded-full"></div>
<!-- Rectangular -->
<div data-skeleton="true" data-skeleton-variant="rectangular" class="h-32 w-full bg-zinc-100 dark:bg-zinc-800 rounded"></div> Variants
The component supports 3 shape variants: text (default), circular, and rectangular.
Text (Default)
Circular
Rectangular
astro
<!-- Text -->
<Skeleton variant="text" width="100%" height={20} />
<!-- Circular -->
<Skeleton variant="circular" width={64} height={64} />
<!-- Rectangular -->
<Skeleton variant="rectangular" width="100%" height={120} /> Animations
Supports `pulse` (default), `wave`, and `none` animations.
Pulse (Default)
Wave
None
astro
<!-- Pulse (Default) -->
<Skeleton animation="pulse" width="100%" height={20} />
<!-- Wave -->
<Skeleton animation="wave" width="100%" height={20} />
<!-- None -->
<Skeleton animation="none" width="100%" height={20} /> Data Attribute Animations
Customize the animation for global attributes using `data-skeleton-animation`.
Pulse (Default)
Wave
None
astro
<!-- Pulse (Default) -->
<div data-skeleton="true" data-skeleton-animation="pulse" class="h-5 w-full bg-zinc-100 dark:bg-zinc-800 rounded"></div>
<!-- Wave -->
<div data-skeleton="true" data-skeleton-animation="wave" class="h-5 w-full bg-zinc-100 dark:bg-zinc-800 rounded"></div>
<!-- None -->
<div data-skeleton="true" data-skeleton-animation="none" class="h-5 w-full bg-zinc-100 dark:bg-zinc-800 rounded"></div> API Reference
| Property | Description | Type | Default |
|---|---|---|---|
| variant | The visual shape variant of the skeleton (circular, rectangular, text). | 'circular' | 'rectangular' | 'text' | 'text' |
| animation | The animation style (pulse, wave, none). | 'pulse' | 'wave' | 'none' | 'pulse' |
| width | Custom width for the skeleton block (e.g., "100%", 200). | string | number | - |
| height | Custom height for the skeleton block (e.g., "100%", 200). | string | number | - |