Sticky Header Covering the Heading You Linked To? Symptom, Cause and Fix
Short answer: When a link such as #pricing scrolls the page, the browser places the target at the very top of the viewport, which is exactly where a fixed or sticky header sits. The cleanest fix is one CSS line on the html element: scroll-padding-top set to the header height plus a little breathing room. It works for every anchor on the page, including skip links and table-of-contents links, with no JavaScript. If your header changes height on small screens, use a custom property so the number is defined once.
What you are seeing
A visitor taps "Prices" in your menu, the page scrolls, and the heading "Our prices" has vanished behind the bar. The first paragraph is visible but the title is not, so the visitor wonders whether the link worked. The same happens when someone follows a shared link ending in a fragment, or when a form error moves focus to a field near the top of the viewport.
Nothing is broken in the browser. It aligns the target with the top edge of the scrolling area and has no idea that a sticky element is covering the first 80 pixels. You have to tell it.
Symptom, cause and fix table
| Symptom | Likely cause | Fix |
|---|---|---|
| Heading hidden under the header after clicking a menu link | Header is position: fixed or sticky and the scroll target is flush with the top |
html { scroll-padding-top: 5rem; } |
| Only one section is affected | That section has its own anchor, and the global rule is overridden or missing | Add scroll-margin-top to that element |
| Fine on desktop, hidden on mobile | Header grows to two lines or gains a banner on narrow screens | Drive the offset from a variable that changes at the same breakpoint |
| Fine until the cookie bar or promo strip shows | A second fixed element stacks above the header | Add its height to the variable, or hide it after dismissal |
| Target lands too low, with a big gap | Offset larger than the header, or padding added twice | Remove the old JavaScript offset or spacer div |
| Smooth scroll stops short | A script scrolls to the element and subtracts its own number | Delete the script and rely on the CSS property |
| Keyboard skip link focuses an element that is covered | Focus scrolling also respects the padding, but the header lacks a z-index fix | Check the padding is set on the scroller and test with Tab |
The one-line fix
Put this in your main stylesheet:
html {
scroll-padding-top: 5rem;
}
scroll-padding-top belongs to the scroll container, not to the targets. Because the page itself scrolls through the html element, setting it there applies to every fragment link and to focus-driven scrolling. Use rem rather than pixels so the offset grows if a visitor raises their default text size, which also tends to make your header taller.
Measure, then add a margin
Open your browser's developer tools, select the header and read its rendered height. Say it is 72 pixels, which is 4.5rem at the common 16 pixel base. Set the padding to 5rem so there is a little air above the heading. Resist the urge to match the height exactly; a heading touching the header edge looks cramped.
One variable for a header that changes
If the header is taller on phones, define the number once:
:root { --header-h: 4.5rem; }
@media (max-width: 40rem) { :root { --header-h: 6rem; } }
html { scroll-padding-top: calc(var(--header-h) + 1rem); }
header { min-height: var(--header-h); }
Now the header and the offset cannot drift apart. When a designer later adds a promo strip, they change one value.
Targeting a single element with scroll-margin
Sometimes one section needs a different offset, for example a heading that sits inside a card with its own top padding. scroll-margin-top lives on the target element:
.card h2[id] { scroll-margin-top: 6.5rem; }
Use the global rule first and the margin only for exceptions. Mixing them everywhere makes later debugging painful, because the two values add together.
Pages where a different element scrolls
Some themes make body or a wrapper div the scrolling element, using overflow: auto and a fixed height. In that case html is not the scroller and the rule does nothing. Check by scrolling the page and watching which element has a scrollbar in the dev tools layers view. Put scroll-padding-top on whichever element actually scrolls. If you can, remove the nested scroller; it also tends to break the mobile address bar behaviour and some browsers' find-in-page.
Testing the fix
- [ ] Click every in-page menu item at desktop width and read the heading in full.
- [ ] Repeat at 375 pixels wide, where the header is usually taller.
- [ ] Open a URL with a fragment typed directly, not only by clicking.
- [ ] Press Tab on a long page until focus moves to something just below the header.
- [ ] Trigger a form validation error on a field near the top.
- [ ] Zoom to 200 percent and confirm the heading still clears the bar.
Old workarounds to delete
Before the CSS property was widely supported, people added an empty div of header height above each section, set a negative top margin with a positive padding trick, or wrote JavaScript that listened for clicks and scrolled by hand. Search your theme for those. If you leave them in place next to the new rule, targets land too low or the browser and the script fight each other, producing a visible jump. As of November 2026 the property is supported in all current major browsers, but check the compatibility table on MDN if you support very old devices.
FAQ
Does this work with smooth scrolling?
Yes. scroll-behavior: smooth animates toward the same final position, and the padding is part of that calculation, so the animation ends with the heading clear of the header.
Will it change how my page looks when nobody clicks a link?
No. The property only affects where scroll snapping and fragment navigation place content, not the layout or the initial scroll position.
My builder has an "offset" field in the menu. Should I use it instead?
If the offset is applied through a script, prefer the CSS rule and clear the field, because two mechanisms stack. If the builder generates the CSS itself, one value is enough.
Does the fixed header also hide content when I press Page Down?
It can, since the browser scrolls by a screen height. Setting scroll-padding-top helps there too in current browsers, because keyboard scrolling respects it.
If your site has menu links that land in the wrong place and you would rather hand the fix over, we can look at it with you through our enquiry page.