Font Family Fallback Stacks
Four common font stacks and a missing-font switch that shows the browser falling back to the next choice.
AI prompt
Typography specimen sheet showing the same sentence in four font stacks in a clean list, a serif stack in Georgia style, a neutral sans stack in system style, a monospace stack and a rounded sans stack, each with the CSS font-family line in small grey monospace underneath and the characters Il1 O0 rn m highlighted to compare ambiguity, off-white background, near-black text, generous spacing. Negative: decorative display fonts, colour, shadows, text errors. Reduced motion: static sheet.About this pattern
Definition
A font stack is a prioritised list: the browser uses the first font that is installed and falls back to the next if not, ending in a generic family such as serif, sans-serif or monospace that always exists. Good stacks keep the page looking right even when the preferred font fails to load.
When to use it
- Put the preferred font first, close alternatives next, and a generic family last.
- system-ui and ui-monospace use the operating system's own fonts and load instantly.
- Choose fallbacks with similar width and x-height so the layout does not jump.
- Always end with a generic family.
What the controls do
- Four stack buttons and a Pretend first font is missing checkbox.
Motion & timing
- The text changes instantly.
- Reduced motion: nothing animates.
Tips & variations
- Test with the preferred font blocked to see what people on slow connections see.
- Use font-display: swap for web fonts and size-adjust to reduce the jump.
Code of this live preview
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Stack"><button data-p="0" aria-pressed="true">Serif</button><button data-p="1" aria-pressed="false">Sans</button><button data-p="2" aria-pressed="false">Mono</button><button data-p="3" aria-pressed="false">Rounded</button></div><div class="sp" id="sp"><h4>The quick brown fox</h4><p>Il1 O0 rn m: tell similar shapes apart.</p></div><pre class="cs" id="cs"></pre><label class="sw"><input id="ms" type="checkbox"> Pretend the first font is missing</label><p class="out" id="out"></p></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}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.sp{border:1px solid var(--line);border-radius:12px;background:var(--surface);padding:12px 14px}.sp h4{font-size:19px;margin-bottom:4px}.sp p{font-size:13px}.cs{font:11px/1.45 'JetBrains Mono',ui-monospace,monospace;background:var(--pv);border-radius:8px;padding:6px 10px;margin:0;white-space:pre-wrap}.sw{display:flex;gap:6px;align-items:center;font-size:12px;color:var(--muted)}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const S=[["Georgia","'Times New Roman'","serif"],["system-ui","-apple-system","'Segoe UI'","sans-serif"],["ui-monospace","Menlo","Consolas","monospace"],["ui-rounded","'SF Pro Rounded'","Nunito","sans-serif"]],sp=document.getElementById('sp'),ms=document.getElementById('ms'),bs=[...document.querySelectorAll('#pre button')];let p=0;
function up(){const st=(ms.checked?["'Missing Font Name'"]:[]).concat(S[p]);sp.style.fontFamily=st.join(',');document.getElementById('cs').textContent='font-family: '+st.join(', ')+';';document.getElementById('out').textContent=ms.checked?'The first name is not installed, so the browser skips it and uses the next one.':'The first installed font in the list is used; the last name is the safe generic.';bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;up();}));ms.addEventListener('change',up);up();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>Font Family Fallback Stacks — 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}}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.sp{border:1px solid var(--line);border-radius:12px;background:var(--surface);padding:12px 14px}.sp h4{font-size:19px;margin-bottom:4px}.sp p{font-size:13px}.cs{font:11px/1.45 'JetBrains Mono',ui-monospace,monospace;background:var(--pv);border-radius:8px;padding:6px 10px;margin:0;white-space:pre-wrap}.sw{display:flex;gap:6px;align-items:center;font-size:12px;color:var(--muted)}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Stack"><button data-p="0" aria-pressed="true">Serif</button><button data-p="1" aria-pressed="false">Sans</button><button data-p="2" aria-pressed="false">Mono</button><button data-p="3" aria-pressed="false">Rounded</button></div><div class="sp" id="sp"><h4>The quick brown fox</h4><p>Il1 O0 rn m: tell similar shapes apart.</p></div><pre class="cs" id="cs"></pre><label class="sw"><input id="ms" type="checkbox"> Pretend the first font is missing</label><p class="out" id="out"></p></div>
</div>
<script>
const S=[["Georgia","'Times New Roman'","serif"],["system-ui","-apple-system","'Segoe UI'","sans-serif"],["ui-monospace","Menlo","Consolas","monospace"],["ui-rounded","'SF Pro Rounded'","Nunito","sans-serif"]],sp=document.getElementById('sp'),ms=document.getElementById('ms'),bs=[...document.querySelectorAll('#pre button')];let p=0;
function up(){const st=(ms.checked?["'Missing Font Name'"]:[]).concat(S[p]);sp.style.fontFamily=st.join(',');document.getElementById('cs').textContent='font-family: '+st.join(', ')+';';document.getElementById('out').textContent=ms.checked?'The first name is not installed, so the browser skips it and uses the next one.':'The first installed font in the list is used; the last name is the safe generic.';bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;up();}));ms.addEventListener('change',up);up();
</script>
</body></html>