Skip to content
IndexRequest a UIAboutContact

Top Navigation

A sticky header that compacts and gains a border as the page scrolls.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Create a sticky top navigation inside a scrollable container. The bar shows a brand mark on the left, four links (Product, Docs, Pricing, Blog) and a primary button on the right. At scroll position 0 it is 72px tall and transparent. After the user scrolls more than 8px it shrinks to 52px over 250ms, gets a translucent background (rgba of the surface colour at 80%) with backdrop-filter: blur(12px) and a 1px bottom border. Links get an underline that scales in from the left on hover. Mark the current page with aria-current="page". Below 640px, hide the links and show a menu button that toggles a dropdown panel with aria-expanded and aria-controls; close it on Escape and when a link is chosen. Use a scroll listener with requestAnimationFrame throttling. Honour prefers-reduced-motion by disabling transitions.

About this pattern

Definition

A horizontal bar at the top of the page holding the brand, the main destinations and one or two actions. In this version it shrinks and gains a blurred background once the content scrolls beneath it.

Purpose & UX principles

  • Gives every page a stable anchor for orientation and for getting back home.
  • Shrinking on scroll returns screen space to the content while keeping navigation one tap away.
  • Keep the visible links to six or fewer. Move extras into a menu.

Interaction states

  • At top: transparent, 72px tall.
  • Scrolled: 52px tall, translucent surface with backdrop blur and a bottom border.
  • Link hover: text brightens and an underline grows from the left.
  • Current page: accent colour and aria-current="page".
  • Menu open (mobile): button shows a close icon and aria-expanded="true".

Motion specification

  • Height and padding: 250ms ease.
  • Background and border: 250ms linear.
  • Underline: scaleX from 0 to 1, 220ms, origin left.
  • Mobile panel: opacity and translateY(-8px), 200ms.
  • Reduced motion: no transitions; state changes are instant.

Responsive behaviour

  • Wide screens: links are shown inline.
  • Under 640px: the links collapse into a menu button that opens a panel under the bar.
  • The bar height changes from 72px to 52px, so reserve the larger height for the page's top padding to avoid layout jumps.

Code

HTML
<div class="frame" id="scroller">
  <header class="topnav" id="bar">
    <a class="brand" href="#">◐ Orbit</a>
    <nav id="links" aria-label="Main"><a href="#" aria-current="page">Product</a><a href="#">Docs</a><a href="#">Pricing</a><a href="#">Blog</a></nav>
    <button class="cta">Sign up</button>
    <button class="burger" id="burger" aria-expanded="false" aria-controls="links" aria-label="Menu">☰</button>
  </header>
  <div class="content"><h2>Scroll this panel</h2><p>The bar above compacts once you scroll.</p><p>Keep scrolling…</p><p>…the border and blur appear.</p><p>Content continues here.</p><p>More content.</p><p>More content.</p><p>More content.</p></div>
</div>

Related patterns

Sidebar

↗
SidebarNavigation

Tab Navigation

↗
Tab NavigationNavigation

Breadcrumb

↗
BreadcrumbNavigation