Skeleton Examples
The examples below assume that you have imported the component and set up the theme.
Basic
Hold the place of a post with a cover image while it loads. An empty <sv-skeleton> is a 1em bar, shape="circle" turns one into an avatar, lines="4" draws four text bars, and inline-size sets the width of each shape.
Your system is set to reduce motion. The placeholder holds still for you.
<div class="skeleton-basic"> <sv-skeleton class="cover"></sv-skeleton>
<div class="row"> <sv-skeleton class="avatar" shape="circle"></sv-skeleton> <div class="lines"> <sv-skeleton class="name"></sv-skeleton> <sv-skeleton></sv-skeleton> </div> </div>
<sv-skeleton class="body" lines="4"></sv-skeleton></div>
<style> .skeleton-basic { display: grid; gap: 1.25em; inline-size: min(100%, 22em); margin-inline: auto;
.row { display: flex; gap: 0.75em; align-items: center; }
.lines { flex: 1; }
.cover { --sv-skeleton-bdr-rad: var(--sv-bdr-rad-md);
display: block; block-size: auto; aspect-ratio: 16 / 9; }
.avatar { inline-size: 2.5em; }
.name { inline-size: 40%; } }</style>Wrap Content
Turn real content into its own placeholder while it loads. Text in <sv-skeleton> gets one rounded bar per line, and display: inline-grid fits the placeholder to the button.
Check loaded to show the content in the same place, with no layout shift.
<article class="skeleton-wrap-content"> <p class="meta"><sv-skeleton>Guide · 5 min read</sv-skeleton></p> <p class="title"><sv-skeleton>Color that works for everyone</sv-skeleton></p> <p> <sv-skeleton> A short guide to picking text and background colors with enough contrast for every reader and screen. </sv-skeleton> </p>
<sv-skeleton class="action"> <button type="button" class="btn btn-primary">Read the guide</button> </sv-skeleton></article>
<style> .skeleton-wrap-content { display: grid; gap: 0.5em; justify-items: start; inline-size: min(100%, 22em); padding: 1.25em; margin: 1em auto; background-color: var(--sv-gray-7); border: 1px solid var(--sv-gray-5); border-radius: var(--sv-bdr-rad-lg);
p { margin: 0; }
.meta { font-size: 0.85em; color: var(--sv-gray-3); }
.title { font-size: 1.2em; font-weight: 600; color: var(--sv-gray-0); }
.action { display: inline-grid; margin-block-start: 0.5em; } }</style>Avoid Flicker
Reload a card with no blink when the request is fast. --sv-skeleton-delay on the card keeps the old numbers on screen during the delay, and a load that ends sooner never shows the placeholder.
Pick a request time, then press Reload.
Weekly sales
<div class="skeleton-avoid-flicker" style="--sv-skeleton-delay: 300ms" data-request-time="1000"> <p class="label">Weekly sales</p> <p class="total"><sv-skeleton loaded>$12,480</sv-skeleton></p> <p class="change"><sv-skeleton loaded>Up 18% from last week</sv-skeleton></p> <button type="button" class="btn reload-button">Reload</button></div>
<script type="application/x-typescript" module> const salesCard = document.querySelector<HTMLElement>(".skeleton-avoid-flicker")!; const skeletons = salesCard.querySelectorAll("sv-skeleton");
salesCard.querySelector(".reload-button")!.addEventListener("click", async () => { for (const skeleton of skeletons) { skeleton.loaded = false; }
const sales = await fetchSales(); salesCard.querySelector(".total sv-skeleton")!.textContent = sales.total; salesCard.querySelector(".change sv-skeleton")!.textContent = sales.change;
for (const skeleton of skeletons) { skeleton.loaded = true; } });
// Stands in for the request, which takes the time in `data-request-time` function fetchSales() { const sales = { total: `$${Math.round(10_000 + Math.random() * 5000).toLocaleString("en-US")}`, change: `Up ${10 + Math.floor(Math.random() * 10)}% from last week`, };
const requestTime = Number(salesCard.dataset.requestTime); return new Promise<typeof sales>(resolve => setTimeout(resolve, requestTime, sales)); }</script>
<style> .skeleton-avoid-flicker { display: grid; gap: 0.25em; justify-items: start; inline-size: min(100%, 18em); padding: 1.25em; margin: 1em auto; background-color: var(--sv-gray-7); border: 1px solid var(--sv-gray-5); border-radius: var(--sv-bdr-rad-lg);
p { margin: 0; }
.label { font-size: 0.9em; color: var(--sv-gray-3); }
.total { font-size: 2em; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--sv-gray-0); }
.change { font-size: 0.9em; font-variant-numeric: tabular-nums; }
.reload-button { margin-block-start: 0.75em; } }</style>