Skip to content
Blog / Sticky Header: When to Use One and How to Build It Right

Sticky Header: When to Use One and How to Build It Right

Abdul Awal Uzzal
Abdul Awal Uzzal
November 24, 2026
10 min read
Tutorial / How to
Sticky Header: When to Use One and How to Build It Right

A sticky header is a site header that stays visible at the top of the screen while the visitor scrolls down the page. Instead of scrolling away with the content, the logo, navigation and main call to action remain one glance away.

Done well, it saves people a trip back to the top every time they want to move on. Done badly, it eats a third of a phone screen, hides focused links and jitters as the page scrolls. This guide builds on our website header design post and covers when a sticky header is worth it, the CSS and JavaScript to build one, and how to set it up in WordPress.

Quick answer: Use a sticky header when visitors scroll long pages and regularly need the navigation, search, cart or a contact button. Build it with position: sticky; top: 0; on the header element, keep it short (roughly 56 to 72 pixels on desktop, less on mobile), give it a solid background and a z-index, and make sure it never hides focused elements or in-page anchor targets.

When a sticky header helps

A sticky header earns its space when people need the header often, not just at the start of the visit. Common cases:

  • Online stores: shoppers move between products, search and the cart constantly, so a persistent cart icon and search field save real effort.
  • Long content and documentation: readers on a 3,000 word guide can jump to another section or page without scrolling back up.
  • Service and lead generation sites: a “Get a quote” or “Book a call” button that stays visible gives interested visitors a way to act the moment they are ready.
  • Web apps and dashboards: account menus and global actions are expected to stay put.

When to skip it

Not every site needs one. Short pages, single-screen landing pages and image-heavy portfolios often look better with a header that scrolls away, because the content gets the full screen. A sticky header is also a poor fit when the header is tall, carries two or three rows (top bar, logo row, menu row) or contains promotional banners. If you cannot make it compact, either make only one row sticky or let it scroll.

SituationSticky header?Why
Ecommerce with search and cartYesFrequent navigation and cart access
Long blog posts and docsUsuallyReaders switch sections and pages
Lead generation service siteUsuallyKeeps the main call to action visible
Short landing pageRarelyLittle scrolling, one action at the bottom
Visual portfolioOptionalFull-screen imagery often matters more
Header with three stacked rowsOnly one rowFull height covers too much content

How to build a sticky header with CSS

Modern browsers support position: sticky, so you no longer need JavaScript to pin a header. A sticky element behaves like a normal element until it reaches the offset you set, then it sticks there while its parent is still on screen. MDN’s reference for the CSS position property covers the details.

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: #ffffff;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

/* Keep anchor targets and focused elements clear of the header */
html {
  scroll-padding-top: 80px;
}

/* Make room for the WordPress admin bar when logged in */
.admin-bar .site-header {
  top: var(--wp-admin--admin-bar--height, 32px);
}

Why position: sticky sometimes does nothing

If you add the CSS above and the header still scrolls away, one of these is almost always the cause:

  1. The header’s parent is not much taller than the header. A sticky element only sticks inside its parent. If the theme wraps the header in its own container, apply sticky to that wrapper instead.
  2. An ancestor has overflow set. overflow: hidden, overflow: auto or overflow-x: hidden on a parent such as body or a page wrapper creates a new scroll container and breaks sticky behavior. Use overflow-x: clip instead where you need to hide horizontal overflow.
  3. No offset is set. Without top: 0 (or another value), sticky has nothing to stick to.
  4. Something covers it. If sliders or dropdowns appear above the header, raise its z-index.

Fixed vs sticky positioning

Older tutorials use position: fixed. A fixed header is taken out of the page flow, so you have to add top padding to the body to stop content hiding underneath it, and the padding has to match the header height at every breakpoint. Sticky keeps the header in the flow, so the space is reserved automatically. Use fixed only when the header must overlay a hero image from the very first pixel.

Add a light shrink effect on scroll

A popular refinement is a header that looks generous at the top of the page and becomes more compact once the visitor scrolls. The cheapest reliable way to detect scrolling is an IntersectionObserver watching a tiny marker element at the top of the page, which avoids running code on every scroll event.

Add an empty marker just before the header in your theme’s header template:

<div class="header-sentinel" aria-hidden="true"></div>
<header class="site-header">
  <a class="site-logo" href="https://example.com/">Brand</a>
  <nav aria-label="Main">...</nav>
</header>

Then the script, loaded with defer or in the footer:

const header = document.querySelector('.site-header');
const sentinel = document.querySelector('.header-sentinel');

if (header && sentinel && 'IntersectionObserver' in window) {
  const observer = new IntersectionObserver(([entry]) => {
    header.classList.toggle('is-scrolled', !entry.isIntersecting);
  });
  observer.observe(sentinel);
}

And the styles for the scrolled state:

.header-sentinel {
  height: 1px;
}

.site-header .site-logo {
  display: inline-block;
  transform-origin: left center;
  transition: transform 0.2s ease;
}

.site-header {
  transition: box-shadow 0.2s ease;
}

.site-header.is-scrolled {
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.site-header.is-scrolled .site-logo {
  transform: scale(0.85);
}

@media (prefers-reduced-motion: reduce) {
  .site-header,
  .site-header .site-logo {
    transition: none;
  }
}

This version scales the logo and adds a shadow rather than changing the header’s padding. Transforms do not change layout, so the page does not jump when the class is added. If you do want the header itself to get shorter, expect a small shift in content and test it carefully near the top of the page, where toggling can flicker.

Sticky header accessibility and mobile tips

A sticky header sits on top of the content, which creates a few accessibility risks that are easy to miss in a design review.

Do not hide the focused element

WCAG 2.2 added a success criterion, Focus Not Obscured (Minimum), which says a keyboard-focused element must not be entirely hidden by content the author created, sticky headers included. Keyboard users tabbing up a page are the ones most likely to hit this. The scroll-padding-top rule in the CSS above tells the browser to keep scrolled-to elements below the header, which fixes most cases. Set it to the header height plus a little breathing room.

Keep the navigation usable

  • Use a real <nav> element with an aria-label, and a real button for the mobile menu toggle with aria-expanded.
  • Make sure the open mobile menu can scroll if it is taller than the screen. A fixed-height menu inside a sticky header can trap links below the fold.
  • Keep a skip link as the first focusable element so keyboard users can jump past the header on every page.
  • Check color contrast in both states if the header changes background on scroll.

Mind the height on phones

On a phone in landscape mode, a 90 pixel header can cover a large share of the visible area. Keep the mobile header to one row, typically 56 to 64 pixels, with the logo, menu button and at most one action such as the cart. Some sites go further and hide the header while the visitor scrolls down, then reveal it on any upward scroll. That pattern gives readers the full screen while keeping navigation one flick away, but it needs more JavaScript and testing, so add it only if a simple compact header is still too intrusive.

How to set up a sticky header in WordPress

You may not need custom code at all. Check what your theme or builder already offers first.

Block themes and the Site Editor

Since WordPress 6.2, Group blocks placed at the top level of a template can use a sticky position setting. Go to Appearance, then Editor, and open the template you want to change. Select the Group block that wraps your header (if the header template part is not wrapped in a Group, select it in List View and add one with Group from the block toolbar). In the block settings sidebar, find Position and choose Sticky. Repeat for each template that should use it, or apply it in the shared parts of your templates so every page behaves the same.

Give the group a background color, otherwise page content will show through as it scrolls underneath.

Classic themes

Many popular classic themes include a sticky header toggle in the Customizer, sometimes as part of a premium add-on. If yours does not, add the CSS from this guide under Appearance, Customize, Additional CSS, changing .site-header to whatever class your theme uses. Your browser’s inspector will show the right selector when you right-click the header and choose Inspect.

Page builders

Elementor Pro, for example, lets you make a header container sticky from its Advanced tab under Motion Effects when you build the header in the Theme Builder. Other builders have similar options. Whatever tool you use, test with the WordPress admin bar visible and hidden, on a real phone, and with the keyboard.

Starting a new site

If you are planning a new build on Webflow or Framer rather than retrofitting an existing theme, starting from a well-designed template saves time on the header, footer and core pages. TNCFlow’s Webflow templates and Framer templates are a reasonable place to start. Whichever template you choose, check how its header behaves on scroll and at mobile widths before you commit, using the checklist above.

Frequently asked questions

What is the difference between a sticky header and a fixed header?

A sticky header stays in the normal page flow until it reaches its offset, then sticks. A fixed header is removed from the flow from the start, so you must add spacing to stop it covering content.

Is a sticky header bad for SEO?

No. Search engines do not penalize sticky headers. A header that covers a large part of a phone screen can hurt usability, though, so keep it compact on mobile.

How tall should a sticky header be?

There is no fixed rule, but roughly 56 to 72 pixels on desktop and 56 to 64 pixels on mobile keeps navigation usable without hiding too much content.

Why is my sticky header not working?

The usual causes are an ancestor with overflow set to hidden or auto, a parent element that is barely taller than the header, or a missing top value. Inspect the parent elements in your browser’s developer tools to find the culprit.

Does a sticky header slow down my site?

The CSS-only version has no measurable performance cost. Scroll effects should use IntersectionObserver or throttled handlers rather than heavy work on every scroll event.

Let’s Talk With us
contact us rotate
Let’s Talk With us
contact us rotate
Let’s Talk With us
contact us rotate