Skeleton Loading
Grey content-shaped placeholders with a soft shimmer while data loads.
AI prompt
Build a card list with a skeleton state. Each card has a 16:9 image area, a title line, two text lines and an avatar with a name line. In the loading state render grey blocks with the same dimensions using a CSS class .sk and a shimmer: a linear-gradient (surface-2, lighter tone, surface-2) at 200% width animated with background-position over 1400ms linear infinite. Set aria-busy="true" on the list while loading. A "Load content" button simulates a 1.6 second request, then fades the real cards in over 200ms and sets aria-busy="false"; a "Reset" button returns to the skeleton. Matching sizes prevents layout shift. Disable the shimmer for prefers-reduced-motion and keep the blocks static.About this pattern
Definition
A placeholder that mimics the layout of content that is still loading: blocks for the image, lines for the text. A soft light sweeps across the blocks to show that the page is alive.
Purpose & UX principles
- Shows the page's structure immediately, so the wait feels shorter and the layout does not jump when content arrives.
- Use for content-heavy areas that take more than about a second; for shorter waits a spinner or nothing is better.
- The skeleton must match the final layout dimensions, otherwise the swap causes a visible shift.
Interaction states
- Loading: skeleton visible, container has
aria-busy="true". - Loaded: real content fades in over the skeleton,
aria-busy="false". - Failed: replace with an inline error and a retry button; never leave a skeleton forever.
Motion specification
- Shimmer: gradient moving across the block, 1400ms linear infinite.
- Content swap: 200ms fade.
- Reduced motion: no shimmer; a static, slightly pulsing opacity is also avoided.
Responsive behaviour
- Build the skeleton from the same grid as the real content so it adapts to the same breakpoints.
- Reserve aspect ratio for images with
aspect-ratio.
Code
<div class="ctl"><button id="load">Load content</button><button id="reset">Reset</button></div>
<div class="cards" id="cards" aria-busy="true"></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
.ctl{display:flex;gap:8px;margin-bottom:16px;justify-content:center}
.ctl button{height:38px;padding:0 16px;border-radius:10px;border:1px solid var(--line);background:var(--surface-2);color:var(--text);font:inherit;font-weight:600;cursor:pointer}
.ctl button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:12px;width:min(520px,100%)}
.card{border:1px solid var(--line);border-radius:14px;background:var(--surface);padding:10px;animation:in .2s ease-out}
.img{aspect-ratio:16/9;border-radius:10px;margin-bottom:10px}
.img.real{background:linear-gradient(135deg,#c9c9c4,#9d9d97)}
.l{height:12px;border-radius:6px;margin-bottom:8px}.l.w{width:80%}.l.s{width:55%}
.who{display:flex;gap:8px;align-items:center;margin-top:12px}.av{width:28px;height:28px;border-radius:50%}.av.real{background:#2563eb}
.sk{background:linear-gradient(100deg,var(--surface-2) 30%,#e2e2de 50%,var(--surface-2) 70%);background-size:200% 100%;animation:sh 1.4s linear infinite}
.t{font-size:14px;font-weight:600;margin-bottom:6px}.p{font-size:12.5px;color:var(--muted)}
@keyframes sh{from{background-position:100% 0}to{background-position:-100% 0}}
@keyframes in{from{opacity:0}}
@media (prefers-reduced-motion:reduce){.sk{animation:none}.card{animation:none}}const cards=document.getElementById('cards');
const sk='<div class="card"><div class="img sk"></div><div class="l w sk"></div><div class="l sk"></div><div class="l s sk"></div><div class="who"><div class="av sk"></div><div class="l s sk" style="margin:0;width:40%"></div></div></div>';
const real=n=>'<div class="card"><div class="img real"></div><div class="t">'+n+'</div><div class="p">A short description of this card goes here.</div><div class="who"><div class="av real"></div><span class="p">Alex Kim</span></div></div>';
function showSk(){cards.setAttribute('aria-busy','true');cards.innerHTML=sk.repeat(3);}
document.getElementById('load').onclick=()=>{showSk();setTimeout(()=>{cards.innerHTML=['Aurora','Basalt','Cirrus'].map(real).join('');cards.setAttribute('aria-busy','false');},1600);};
document.getElementById('reset').onclick=showSk;showSk();One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Skeleton Loading — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
.ctl{display:flex;gap:8px;margin-bottom:16px;justify-content:center}
.ctl button{height:38px;padding:0 16px;border-radius:10px;border:1px solid var(--line);background:var(--surface-2);color:var(--text);font:inherit;font-weight:600;cursor:pointer}
.ctl button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:12px;width:min(520px,100%)}
.card{border:1px solid var(--line);border-radius:14px;background:var(--surface);padding:10px;animation:in .2s ease-out}
.img{aspect-ratio:16/9;border-radius:10px;margin-bottom:10px}
.img.real{background:linear-gradient(135deg,#c9c9c4,#9d9d97)}
.l{height:12px;border-radius:6px;margin-bottom:8px}.l.w{width:80%}.l.s{width:55%}
.who{display:flex;gap:8px;align-items:center;margin-top:12px}.av{width:28px;height:28px;border-radius:50%}.av.real{background:#2563eb}
.sk{background:linear-gradient(100deg,var(--surface-2) 30%,#e2e2de 50%,var(--surface-2) 70%);background-size:200% 100%;animation:sh 1.4s linear infinite}
.t{font-size:14px;font-weight:600;margin-bottom:6px}.p{font-size:12.5px;color:var(--muted)}
@keyframes sh{from{background-position:100% 0}to{background-position:-100% 0}}
@keyframes in{from{opacity:0}}
@media (prefers-reduced-motion:reduce){.sk{animation:none}.card{animation:none}}
</style></head>
<body><div class="stage">
<div class="ctl"><button id="load">Load content</button><button id="reset">Reset</button></div>
<div class="cards" id="cards" aria-busy="true"></div>
</div>
<script>
const cards=document.getElementById('cards');
const sk='<div class="card"><div class="img sk"></div><div class="l w sk"></div><div class="l sk"></div><div class="l s sk"></div><div class="who"><div class="av sk"></div><div class="l s sk" style="margin:0;width:40%"></div></div></div>';
const real=n=>'<div class="card"><div class="img real"></div><div class="t">'+n+'</div><div class="p">A short description of this card goes here.</div><div class="who"><div class="av real"></div><span class="p">Alex Kim</span></div></div>';
function showSk(){cards.setAttribute('aria-busy','true');cards.innerHTML=sk.repeat(3);}
document.getElementById('load').onclick=()=>{showSk();setTimeout(()=>{cards.innerHTML=['Aurora','Basalt','Cirrus'].map(real).join('');cards.setAttribute('aria-busy','false');},1600);};
document.getElementById('reset').onclick=showSk;showSk();
</script>
</body></html>