Sticky header

스티키 헤더

A header that stays pinned to the top of the viewport as you scroll. Made with a single position: sticky.

Also known as: Fixed headerPinned header
···
html
<div class="phone">
  <div class="scroller" id="scroller">
    <header>Header — sticky top:0</header>
    <div class="body">
      <i class="ln"></i><i class="ln"></i><i class="ln"></i><i class="ln"></i>
      <i class="ln"></i><i class="ln"></i><i class="ln"></i><i class="ln"></i>
      <i class="ln"></i><i class="ln"></i><i class="ln"></i><i class="ln"></i>
    </div>
  </div>
</div>
css
.phone{width:min(60%,220px);height:min(92%,300px);border:1px solid var(--line);border-radius:16px;overflow:hidden;
  box-shadow:0 8px 24px rgba(0,0,0,.12);background:var(--bg)}
.scroller{height:100%;overflow-y:auto;scrollbar-width:none}
.scroller::-webkit-scrollbar{display:none}
header{position:sticky;top:0;background:var(--accent);color:#fff;font-size:11px;font-weight:700;
  padding:12px;text-align:center;z-index:1}
.body{padding:14px;display:flex;flex-direction:column;gap:14px}
.ln{display:block;height:14px;border-radius:4px;background:var(--surface);border:1px solid var(--line)}
js
const scroller = document.getElementById('scroller');
let dir = 1;
function tick() {
  const max = scroller.scrollHeight - scroller.clientHeight;
  scroller.scrollTop += dir * 1.1;
  if (scroller.scrollTop >= max) dir = -1;
  if (scroller.scrollTop <= 0) dir = 1;
  requestAnimationFrame(tick);
}
requestAnimationFrame(tick);

position: fixed removes an element from the scroll flow entirely and pins it in place always; position: sticky is a hybrid — it stays in its normal spot until scrolling passes that point, then locks. That's why a sticky header flows normally at the top of the page and only sticks once you've scrolled past it.

You need exactly three things: position: sticky, a top: 0 (the point it sticks to), and no overflow: hidden on any ancestor — that silently breaks sticky entirely. Watch z-index too, or content beneath can render above the header.

Hide-on-scroll-down, show-on-scroll-up headers need more than sticky alone — you listen to the scroll event and drive transform: translateY yourself.

When to use

Use it for controls users need throughout a scroll — navigation, search, filters. On small mobile screens, keep it short so it doesn't eat too much of the viewport.