Back to Blog

What Is a Sticky Header & Should Your Site Have One?

TL;DRA sticky header stays visible at the top of the screen as visitors scroll. It earns its space when it keeps something useful in reach, such as navigation, search, a cart or a primary call to action. Keep it slim, especially on mobile, give it a solid background with strong contrast, and make sure it never hides focused elements or anchor targets (WCAG 2.4.11 Focus Not Obscured). In CSS, position: sticky with scroll-padding-top handles most of this cleanly.

A sticky header, also called a fixed or persistent header, stays at the top of the viewport while the rest of the page scrolls beneath it. Done well, it keeps navigation and key actions one tap away. Done badly, it takes up valuable screen space, covers content and creates accessibility problems.

sticky header

Here’s how to decide whether your site needs one, and how to build it so it helps rather than gets in the way.

When a sticky header makes sense

A sticky header is worth the space when visitors need what’s in it while they scroll:

  • E-commerce stores, where search, the cart and account links are used throughout a visit
  • Long pages and content-heavy sites, where scrolling back to the top to navigate is tedious
  • Service businesses with one primary action, such as “Book an appointment” or “Call us,” that should always be in reach
  • Web applications, where the header holds tools people use constantly

It adds less value on short pages, on landing pages built around a single scroll path, and when the header contains only a logo. If you’re unsure, test it: compare engagement with navigation and calls to action with and without the sticky behavior.

Keep it in proportion

Every pixel the header occupies is a pixel of content the visitor can’t see. On desktop, a sticky header can usually be slimmer than the full header shown at the top of the page; many sites shrink the logo and padding once the visitor scrolls. If you animate that change, keep it smooth and quick, and don’t let the layout jump.

On mobile, space is much tighter:

  • Keep the sticky header to a single slim row with only the essentials, such as the logo, menu button and one key action.
  • Consider a header that hides when the visitor scrolls down and reappears when they scroll up. This keeps navigation available without permanently covering content.
  • Check landscape orientation, where a header that looks fine in portrait can cover a large share of the screen.
  • Check the page at 200% and 400% zoom. At high zoom levels a sticky header can fill most of the viewport, which conflicts with WCAG 1.4.10 Reflow. Many sites switch off the sticky behavior at small viewport heights.

Make the controls easy to tap. WCAG 2.5.8 Target Size (Minimum) sets 24 by 24 CSS pixels as the minimum, and Apple and Google’s platform guidelines recommend larger targets of around 44 to 48 pixels.

Use a solid background and strong contrast

Translucent or transparent sticky headers look elegant in a mockup, but as content scrolls underneath, the text and icons in the header can become hard to read. Use a solid background, or one opaque enough that the contrast stays reliable, and check that text meets WCAG’s 4.5:1 ratio and icons meet 3:1. Apply the same standard to dropdown menus that open from the header.

Don’t hide focused elements or anchor targets

This is the most common accessibility failure with sticky headers. When a keyboard user tabs through a page, the browser scrolls each focused link or field into view, but a sticky header can sit right on top of it. WCAG 2.2 added success criterion 2.4.11 Focus Not Obscured (Minimum), Level AA, which requires that an element receiving keyboard focus is not entirely hidden by author-created content such as a sticky header, cookie banner or chat widget. The stricter Level AAA version, 2.4.12, requires that no part of it is hidden.

The same problem affects in-page links. When someone selects a link to a section further down the page, the section heading can end up hidden under the header.

CSS handles both. scroll-padding-top tells the browser to leave room at the top of the viewport when it scrolls to an anchor target or a focused element:

:root {
  --header-height: 72px;
}

html {
  scroll-padding-top: calc(var(--header-height) + 1rem);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
}

@media (max-width: 767px) {
  :root {
    --header-height: 56px;
  }
}

If the header changes height as the visitor scrolls, update the variable with JavaScript so the offset stays accurate. Then test by tabbing through the whole page with a keyboard and confirming that every focused element remains visible.

Building it: sticky versus fixed

position: sticky is usually the better choice. The header stays in the normal document flow until it reaches the top of the viewport, then sticks, so you don’t need to add padding to the body to stop content sliding underneath it. position: fixed removes the header from the flow entirely and needs that compensating space.

A few things to watch for:

  • A sticky element only sticks within its parent. If the header is wrapped in a container that ends early, it will scroll away with it.
  • An ancestor with overflow: hidden or overflow: auto can stop sticky positioning from working.
  • Set a z-index so dropdowns and page content don’t render on top of the header, and check it against modals, cookie banners and chat widgets.
  • In WordPress, logged-in users see the admin bar at the top of the screen. Offset the header with top: var(--wp-admin--admin-bar--height, 0) or a similar rule so it doesn’t sit underneath it.

Keep motion calm

Header animations should be subtle. Avoid headers that bounce, slide in from unexpected places or change size abruptly, and respect the prefers-reduced-motion setting for visitors who have asked their device to minimize animation. A header that hides and reappears should respond to the visitor’s own scrolling, not to a timer.

Should your site have one?

Ask what the visitor needs to reach while scrolling. If the answer is navigation, search, a cart or a primary call to action, a well-built sticky header helps. If the header holds only a logo, it’s taking space without giving anything back.

Need a header that works on every device and meets WCAG 2.2? Hey Reliable’s front-end development team builds navigation that’s accessible, fast and tested across browsers and screen sizes. Get a proposal for your project.

Get started now

Start with a risk-free, no obligation proposal delivered to your inbox in one business day or less.

Get Started
  • 5-Star Rated Technical Partner
  • 100% White-Label - Sign our NDA
  • 90-Day Code Guarantee
Hey Reliable logo

Welcome to Hey Reliable

We’d love to hear from you. Please use the form below or email info@heyreliable.com.

"*" indicates required fields

This field is for validation purposes and should be left unchanged.
Secret Link