Skeleton
A placeholder with the shape of the content that is loading. It only appears after 150ms, so a fast load doesn't make the screen flash.
Showcase
<LnxSkeleton />variant
SkeletonVariantThe shape: a line of text, a title, small text, a circle or a rectangle Default value: SKELETON_VARIANTS.TEXTheight
stringAny CSS height. By default, the height of the text of the variant, or `size` Default value: undefinedWhen to use
- While a list, a card or a page loads, with the shape of what will come, so nothing jumps when it arrives.
- For an action that is running, like saving, use the
is-loadingof the Button instead. - Mark the container that is loading with
aria-busy="true": skeletons arearia-hidden, so screen readers skip them.
Examples
Shapes
The heights come from the font sizes of the theme.
vue
<div style="display: grid; gap: 12px; width: 100%">
<LnxSkeleton variant="title" width="40%" />
<LnxSkeleton />
<LnxSkeleton variant="small" width="70%" />
<LnxSkeleton variant="circle" size="40px" />
<LnxSkeleton variant="rect" height="75px" />
</div>1
2
3
4
5
6
7
2
3
4
5
6
7
Paragraph
lines stacks several lines, the last one shorter.
vue
<LnxSkeleton :lines="3" />1
Loading and arriving
Add the lnx-appear class to what replaces the skeleton, so it fades in instead of popping.
vue
<div :aria-busy="isLoading" style="display: grid; gap: 12px; width: 100%">
<LnxSkeleton v-if="isLoading" :lines="2" />
<p v-else class="lnx-appear" style="margin: 0">
The minutes of the last meeting are ready to sign.
</p>
<LnxButton mode="outline" @click="isLoading = !isLoading">
{{ isLoading ? 'Finish loading' : 'Load again' }}
</LnxButton>
</div>1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
Any element
The lnx-skeleton class turns any element into a skeleton without changing its markup, hiding what it has inside. Add lnx-skeleton--title, --small, --circle or --rect for the other shapes.
vue
<LnxButton class="lnx-skeleton" style="width: 120px; height: var(--lnx-control-height)">
Save
</LnxButton>1
2
3
2
3
API
Props
| Prop | Type | Description |
|---|---|---|
variant | SkeletonVariant | The shape: a line of text, a title, small text, a circle or a rectangle Default: SKELETON_VARIANTS.TEXT |
lines | number | Number of lines, for a paragraph. The last one is shorter Default: 1 |
width | string | Any CSS width. By default, the whole width, or size |
height | string | Any CSS height. By default, the height of the text of the variant, or size |
size | string | Width and height at once, for circles and squares |
Styles
| Variable | What it sets |
|---|---|
--lnx-skeleton-color | Background of the skeleton |
--lnx-skeleton-shine | Color of the shine that sweeps it |
Types
SkeletonVariant
ts
export const SKELETON_VARIANTS = {
TEXT: 'text', // A line of body text
TITLE: 'title', // A line of a title
SMALL: 'small', // A line of small text
CIRCLE: 'circle', // An avatar or an icon
RECT: 'rect', // An image, a card or a chart
} as const;
export type SkeletonVariant = ValueOf<typeof SKELETON_VARIANTS>;1
2
3
4
5
6
7
8
2
3
4
5
6
7
8