Sticky Footer Layout
A footer that sits at the bottom of the screen on short pages and moves down naturally on long ones.
AI prompt
Clean wireframe diagram comparing two phone-shaped page layouts side by side, the left labelled Without the fix with a short article and the footer floating in the middle of the screen with an empty gap below, the right labelled With the fix with the same short article and the footer attached to the bottom edge, thin outlines and soft grey fills, small arrows showing the main area stretching. Negative: gradients, clutter, text errors. Reduced motion: static diagram.About this pattern
Definition
On a page with little content, a footer placed after it floats halfway up the screen and leaves an ugly gap below. A sticky footer layout makes the page at least as tall as the viewport and lets the main area absorb the extra space, so the footer sits at the bottom, then gets pushed down when content grows.
Purpose & UX principles
- Make the page a flex column with min-height of 100vh (or 100dvh on mobile).
- Give main flex: 1 so it grows to fill the free space.
- The footer needs no fixed or absolute positioning, so it never covers content.
- Test with very short and very long pages.
Interaction states
- Choose how much content the page has, and toggle the fix.
Motion specification
- The page re-flows instantly.
- Reduced motion: no animation.
Responsive behaviour
- Do not confuse this with a fixed footer, which stays on screen and covers content.
- Use dvh so mobile browser bars do not create extra scroll.
Code
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Content"><button data-p="0" aria-pressed="true">Short page</button><button data-p="1" aria-pressed="false">Medium</button><button data-p="2" aria-pressed="false">Long</button></div><label class="sw"><input id="fx" type="checkbox" checked> Sticky footer fix</label><div class="vp"><div class="pg2" id="pg2"><header>Header</header><main id="mn"></main><footer>Footer</footer></div></div></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}
.vp{height:150px;border:2px solid #171717;border-radius:12px;overflow:auto;background:#fff}.pg2{display:block;font-size:11px}.pg2.fx{display:flex;flex-direction:column;min-height:100%}.pg2>*{padding:8px 10px}.pg2 header{background:#dfe6f3;font-weight:700}.pg2 main{background:#fff}.pg2.fx main{flex:1}.pg2 footer{background:#262629;color:#fff}.pg2 p{margin:0 0 6px;height:8px;border-radius:4px;background:#e6e6e2}.pg2 p:nth-child(3n){width:70%}.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 pg=document.getElementById('pg2'),mn=document.getElementById('mn'),fx=document.getElementById('fx'),bs=[...document.querySelectorAll('#pre button')],N=[3,9,24];let p=0;
function up(){mn.innerHTML=Array.from({length:N[p]},()=>'<p></p>').join('');pg.classList.toggle('fx',fx.checked);bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;up();}));fx.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>Sticky Footer Layout — 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}
.vp{height:150px;border:2px solid #171717;border-radius:12px;overflow:auto;background:#fff}.pg2{display:block;font-size:11px}.pg2.fx{display:flex;flex-direction:column;min-height:100%}.pg2>*{padding:8px 10px}.pg2 header{background:#dfe6f3;font-weight:700}.pg2 main{background:#fff}.pg2.fx main{flex:1}.pg2 footer{background:#262629;color:#fff}.pg2 p{margin:0 0 6px;height:8px;border-radius:4px;background:#e6e6e2}.pg2 p:nth-child(3n){width:70%}.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="Content"><button data-p="0" aria-pressed="true">Short page</button><button data-p="1" aria-pressed="false">Medium</button><button data-p="2" aria-pressed="false">Long</button></div><label class="sw"><input id="fx" type="checkbox" checked> Sticky footer fix</label><div class="vp"><div class="pg2" id="pg2"><header>Header</header><main id="mn"></main><footer>Footer</footer></div></div></div>
</div>
<script>
const pg=document.getElementById('pg2'),mn=document.getElementById('mn'),fx=document.getElementById('fx'),bs=[...document.querySelectorAll('#pre button')],N=[3,9,24];let p=0;
function up(){mn.innerHTML=Array.from({length:N[p]},()=>'<p></p>').join('');pg.classList.toggle('fx',fx.checked);bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;up();}));fx.addEventListener('change',up);up();
</script>
</body></html>