Markup
What becomes what
- Text becomes one bar per line.
img,video,canvas,svg,iframeand form fields become a block, and so do CSS icons drawn through a mask, like Nuxt UI'sUIcon.- A painted element with text, up to about three lines tall, counts as a chip or button and becomes one block.
- Table cells and elements with a divider on one side become bars.
Toggle the switches to see each rule at work:
<template>
<Skeleton :loading>
<UAvatar src="/emily.png" size="xl" />
<h4>Emily Johnson</h4>
<UBadge data-skeleton-skip label="Admin" />
<p data-skeleton-block>
Text becomes one bar per line, the avatar and the button become blocks.
</p>
<UButton label="Follow" />
</Skeleton>
</template>
Attributes
| Attribute | Effect |
|---|---|
data-skeleton-block | draw the element as one block |
data-skeleton-skip | leave the element out |
Your own skeleton
A chart, a logo or a canvas doesn't measure well. Use the #skeleton slot to draw your own instead, and build it from <SkeletonBox>, which follows the same colors and shimmer as every other skeleton. It takes width, height and radius.
<template>
<Skeleton :loading>
<RevenueChart />
<template #skeleton>
<SkeletonBox width="100%" :height="128" />
</template>
</Skeleton>
</template>
Height
To fill the height of the parent, give the root a height:
<template>
<div class="flex h-48 flex-col">
<Skeleton class="min-h-0 flex-1" :loading>
<div class="h-full overflow-auto">
<p v-for="row in 12" :key="row">Row {{ row }}</p>
</div>
</Skeleton>
</div>
</template>
Margins of the content stay inside <Skeleton> and don't collapse with its neighbours.
Side effects in the slot
Slot content mounts once for the skeleton and again for the content. Keep data fetching and subscriptions outside <Skeleton>.
When a component in the slot can't avoid them, useInSkeleton() tells it which copy it is in. It's true in the copy the skeleton is measured from:
<script setup lang="ts">
const inSkeleton = useInSkeleton()
// The sample would otherwise ask for sources too
const sources = useQuery({ queryKey: ['sources', props.id], queryFn: fetchSources, enabled: !inSkeleton })
</script>
Text that's only read to screen readers, like Tailwind's sr-only, sits in a clipped 1px box and draws no bone.