Sticky Sidebar Article Layout
A long article with a sidebar card that stays in view while the text scrolls, and a switch to compare without sticky.
AI prompt
Clean wireframe of a long-form article page with a wide main column of text lines and a narrow right sidebar card titled In this article with four links, shown in three vertical positions as the page scrolls with the sidebar staying pinned near the top while the text moves up, small arrows indicating scroll direction, thin outlines and soft grey fills, light theme. Negative: gradients, clutter, text errors. Reduced motion: static diagram.About this pattern
Definition
On long pages a side panel such as a summary, table of contents or call to action should stay visible while the reader scrolls. position: sticky does this without JavaScript: the panel flows with the page until it reaches its top offset, then holds, and stops again when its column ends.
When to use it
- Use a two-column grid; give the aside align-self: start so it does not stretch the full height.
- Set position: sticky and top: with space for any fixed header.
- Make sure no ancestor has overflow hidden that breaks stickiness.
- Collapse to one column on small screens and place the aside after the article.
What the controls do
- Scroll the article area; switch Sticky on or off.
Motion & timing
- Nothing animates by itself.
- Reduced motion: no animation is involved.
Tips & variations
- A sticky panel taller than the viewport becomes unreachable; keep it short or scrollable.
- Keep the reading order logical in the HTML.
Code of this live preview
<div class="bx"><div class="sc" id="sc"><div class="gd"><article><h4>A long read</h4><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p></article><aside id="as"><b>In this article</b><span>Intro</span><span>Method</span><span>Results</span><span>Notes</span></aside></div></div><label class="sw"><input id="st" type="checkbox" checked> Sticky sidebar</label></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}
.sc{height:176px;overflow:auto;border:1px solid var(--line);border-radius:12px;background:#fff;padding:10px}.gd{display:grid;grid-template-columns:minmax(0,1fr) 92px;gap:12px;align-items:start}article h4{margin:0 0 8px;font-size:14px}article p{height:34px;margin:0 0 8px;border-radius:5px;background:repeating-linear-gradient(#e6e6e2 0 6px,transparent 6px 11px)}aside{display:grid;gap:4px;font-size:11px;background:#f4f4f1;border:1px solid var(--line);border-radius:10px;padding:8px}aside.s{position:sticky;top:0}aside b{font-size:11.5px}aside span{color:var(--muted)}.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 as=document.getElementById('as'),st=document.getElementById('st');function up(){as.classList.toggle('s',st.checked);}st.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 Sidebar Article 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}
.sc{height:176px;overflow:auto;border:1px solid var(--line);border-radius:12px;background:#fff;padding:10px}.gd{display:grid;grid-template-columns:minmax(0,1fr) 92px;gap:12px;align-items:start}article h4{margin:0 0 8px;font-size:14px}article p{height:34px;margin:0 0 8px;border-radius:5px;background:repeating-linear-gradient(#e6e6e2 0 6px,transparent 6px 11px)}aside{display:grid;gap:4px;font-size:11px;background:#f4f4f1;border:1px solid var(--line);border-radius:10px;padding:8px}aside.s{position:sticky;top:0}aside b{font-size:11.5px}aside span{color:var(--muted)}.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="sc" id="sc"><div class="gd"><article><h4>A long read</h4><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p></article><aside id="as"><b>In this article</b><span>Intro</span><span>Method</span><span>Results</span><span>Notes</span></aside></div></div><label class="sw"><input id="st" type="checkbox" checked> Sticky sidebar</label></div>
</div>
<script>
const as=document.getElementById('as'),st=document.getElementById('st');function up(){as.classList.toggle('s',st.checked);}st.addEventListener('change',up);up();
</script>
</body></html>