Skeleton loader
VSkeletonLoader reserves space for loading content. It is decorative by default; mark the containing region with aria-busy.
Usage
<script setup lang="ts">
import { VSkeletonLoader } from 'vectis-ui'
</script>
<template>
<div class="demo">
<VSkeletonLoader :lines="3" />
</div>
</template>
<style scoped>
.demo {
inline-size: 22rem;
}
</style>Examples
Shapes
Choose a shape for text, controls, pills, circles or surfaces. Override dimensions with width and height.
<script setup lang="ts">
import { VSkeletonLoader, type SkeletonLoaderShape } from 'vectis-ui'
const shapes: SkeletonLoaderShape[] = ['text', 'control', 'pill', 'circle', 'surface']
</script>
<template>
<div class="demo">
<div v-for="shape in shapes" :key="shape" class="row">
<p class="caption">{{ shape }}</p>
<VSkeletonLoader :shape="shape" />
</div>
<div class="row">
<p class="caption">width</p>
<VSkeletonLoader shape="control" :width="180" />
<VSkeletonLoader shape="control" width="60%" />
</div>
<div class="row">
<p class="caption">height</p>
<VSkeletonLoader shape="surface" :height="48" />
</div>
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-5);
inline-size: 22rem;
}
.row {
display: grid;
gap: var(--vectis-space-2);
}
.caption {
margin: 0;
color: var(--vectis-color-text-muted);
font-size: var(--vectis-text-caption-size);
}
</style>Sizes
size applies to control, pill and circle shapes.
<script setup lang="ts">
import { VSkeletonLoader, type SkeletonLoaderSize } from 'vectis-ui'
const sizes: SkeletonLoaderSize[] = ['xs', 'sm', 'md', 'lg', 'xl']
</script>
<template>
<div class="demo">
<div class="row">
<p class="caption">circle</p>
<div class="inline">
<VSkeletonLoader v-for="size in sizes" :key="size" shape="circle" :size="size" />
</div>
</div>
<div class="row">
<p class="caption">control</p>
<VSkeletonLoader v-for="size in sizes" :key="size" shape="control" :size="size" />
</div>
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-5);
inline-size: 18rem;
}
.row {
display: grid;
gap: var(--vectis-space-2);
}
.inline {
display: flex;
align-items: start;
gap: var(--vectis-space-3);
}
.caption {
margin: 0;
color: var(--vectis-color-text-muted);
font-size: var(--vectis-text-caption-size);
}
</style>Paragraphs of text
lines stacks placeholders. In the text shape, the last line is shorter.
<script setup lang="ts">
import { VSkeletonLoader } from 'vectis-ui'
</script>
<template>
<div class="demo">
<div class="body">
<p class="caption">body-sm, 5 lines</p>
<VSkeletonLoader :lines="5" />
</div>
<div class="heading">
<p class="caption">heading-2, 2 lines</p>
<VSkeletonLoader :lines="2" />
</div>
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-6);
inline-size: 24rem;
}
.body {
font-size: var(--vectis-text-body-sm-size);
line-height: var(--vectis-text-body-sm-leading);
}
.heading {
font-size: var(--vectis-text-heading-2-size);
line-height: var(--vectis-text-heading-2-leading);
}
.caption {
margin: 0 0 var(--vectis-space-2);
color: var(--vectis-color-text-muted);
font-size: var(--vectis-text-caption-size);
line-height: var(--vectis-text-caption-leading);
}
</style>The silhouette of a real component
Compose shapes to match the content that will replace them.
Component
Skeleton
ALActive filter
Sales analysis
The quarter closes on a 12% rise in revenue.
<script setup lang="ts">
import { VAvatar, VButton, VChip, VInput, VSkeletonLoader, VTypography } from 'vectis-ui'
</script>
<template>
<div class="grid">
<VTypography variant="overline" tone="muted" as="p">Component</VTypography>
<VTypography variant="overline" tone="muted" as="p">Skeleton</VTypography>
<VButton size="md">Save</VButton>
<VSkeletonLoader shape="control" size="md" :width="128" />
<VAvatar size="lg" name="Ada Lovelace" />
<VSkeletonLoader shape="circle" size="lg" />
<VChip size="xs">Active filter</VChip>
<VSkeletonLoader shape="pill" size="xs" :width="88" />
<VInput size="md" label="Name" model-value="Ada Lovelace" />
<div class="field">
<VSkeletonLoader width="40%" />
<VSkeletonLoader shape="control" size="md" />
</div>
<div class="card">
<VTypography variant="heading-4">Sales analysis</VTypography>
<VTypography variant="body-sm" tone="muted">
The quarter closes on a 12% rise in revenue.
</VTypography>
</div>
<div class="card">
<VSkeletonLoader shape="control" size="sm" width="60%" />
<VSkeletonLoader :lines="3" />
</div>
</div>
</template>
<style scoped>
.grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: var(--vectis-space-6) var(--vectis-space-8);
align-items: start;
inline-size: 100%;
}
.field,
.card {
display: grid;
gap: var(--vectis-space-3);
}
.card {
padding: var(--vectis-space-4);
border: 1px solid var(--vectis-color-border);
border-radius: var(--vectis-radius-surface);
}
</style>Animations
Choose a wave, pulse or no animation. Reduced motion replaces the wave with a slower pulse.
<script setup lang="ts">
import { VSkeletonLoader, type SkeletonLoaderAnimation } from 'vectis-ui'
const animations: SkeletonLoaderAnimation[] = ['wave', 'pulse', 'none']
</script>
<template>
<div class="demo">
<div v-for="animation in animations" :key="animation" class="row">
<p class="caption">{{ animation }}</p>
<VSkeletonLoader shape="surface" :animation="animation" />
</div>
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-5);
inline-size: 22rem;
}
.row {
display: grid;
gap: var(--vectis-space-2);
}
.caption {
margin: 0;
color: var(--vectis-color-text-muted);
font-size: var(--vectis-text-caption-size);
}
</style>A colour of your own
color sets a custom background colour.
<script setup lang="ts">
import { VSkeletonLoader } from 'vectis-ui'
</script>
<template>
<div class="demo">
<VSkeletonLoader shape="surface" color="oklch(55% 0.14 265)" />
<div class="inverse">
<VSkeletonLoader shape="control" size="sm" width="60%" color="oklch(38% 0.01 260)" />
<VSkeletonLoader :lines="3" color="oklch(38% 0.01 260)" />
</div>
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-5);
inline-size: 22rem;
}
.inverse {
display: grid;
gap: var(--vectis-space-3);
padding: var(--vectis-space-4);
border-radius: var(--vectis-radius-surface);
background: var(--vectis-color-surface-inverse);
}
</style>Replacing the skeleton
Replace the skeleton with v-if when content is ready. Keep aria-busy on the containing region while loading.
<script setup lang="ts">
import { ref } from 'vue'
import { VButton, VSkeletonLoader, VTypography } from 'vectis-ui'
const pending = ref(true)
</script>
<template>
<div class="demo">
<VButton size="sm" variant="outline" tone="neutral" @click="pending = !pending">
{{ pending ? 'Load' : 'Reload' }}
</VButton>
<div class="zone" :aria-busy="pending || undefined">
<template v-if="pending">
<VSkeletonLoader shape="control" size="sm" width="55%" />
<VSkeletonLoader :lines="3" />
</template>
<template v-else>
<VTypography variant="heading-4">Sales analysis</VTypography>
<VTypography variant="body-sm" tone="muted">
The quarter closes on a 12% rise in revenue, driven by annual subscriptions.
</VTypography>
</template>
</div>
</div>
</template>
<style scoped>
.demo {
display: grid;
justify-items: start;
gap: var(--vectis-space-4);
inline-size: 24rem;
}
.zone {
display: grid;
gap: var(--vectis-space-3);
inline-size: 100%;
}
</style>Announcing the wait
Use announce or label to announce one loading indicator. Avoid announcing every skeleton in the same region.
<script setup lang="ts">
import { VSkeletonLoader } from 'vectis-ui'
</script>
<template>
<div class="demo">
<!-- Announce only one skeleton per loading region. -->
<VSkeletonLoader shape="control" size="sm" label="Loading the results" />
<VSkeletonLoader v-for="n in 7" :key="n" shape="control" size="sm" />
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-2);
inline-size: 20rem;
}
</style>API
Props
CSS variables