Skip to content
IndexRequest a UIAboutContact

Sticky Header that Shrinks

A header that stays at the top and shrinks with a soft shadow once you scroll, giving content more room.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Design a sticky site header inside a scrollable page. At the top it is 72 pixels tall with a 28 pixel logo mark, the wordmark "Atlas" and three links on the right; after scrolling more than 16 pixels it shrinks to 48 pixels, the logo scales to 20 pixels, and a soft shadow and bottom border appear. The transition takes 200 milliseconds with an ease-out and does not move the page content (content has a constant top offset). Use position sticky, a single scrolled class toggled from a passive scroll listener, links with visible focus outlines, and a prefers-reduced-motion fallback with no transition. The page below contains several placeholder content blocks so scrolling can be tested. Plain HTML, CSS and JavaScript.

About this pattern

Definition

A shrinking sticky header stays visible while the page scrolls and becomes more compact after the first few pixels, so navigation is always available without taking too much space.

Purpose & UX principles

  • Keeps navigation reachable on long pages while returning vertical space to content.
  • Add a subtle shadow or border only after scrolling starts so the header separates from content.
  • Avoid layout shifts: shrink with transforms or fixed heights and keep the content offset constant.

Interaction states

  • Top of page (tall, no shadow), scrolled (compact, shadow), focus within header.

Motion specification

  • Height, logo scale and shadow change over 200ms; the listener uses a passive scroll handler and a single class toggle.
  • Reduced motion: the header changes size instantly.

Responsive behaviour

  • On phones keep the compact height (48 to 56px) from the start; shrinking matters mostly on desktop.
  • Account for the header height when linking to in-page anchors (scroll-margin-top).

Code

HTML
<div class="pg" id="pg"><header class="hd" id="hd"><span class="lg"><i></i><b>Atlas</b></span><nav aria-label="Main"><a href="#" onclick="return false">Work</a><a href="#" onclick="return false">About</a><a href="#" onclick="return false">Contact</a></nav></header><main><div class="bl"></div><div class="bl"></div><div class="bl"></div><div class="bl"></div><div class="bl"></div></main></div>

Related patterns

Reading Progress Bar

↗
Reading Progress BarLayout & Scrolling

Top Navigation

↗
Top NavigationNavigation

Pointer Parallax Layers

↗
Pointer Parallax LayersMotion & Transitions