Sphere
Log in Join
☆ 13

Sticky header covers anchor targets

Clicking a link to #pricing scrolls the heading under my fixed 64px header. Setting scroll-margin-top on headings did not work in one browser.

⚑ Report

3 replies

☆ 0
M Mara ·2026-10-26#1

Use scroll-margin-top on the target element and scroll-padding-top on the scroll container. Setting both covers browsers that handle one differently.

⚑ Report
☆ 0
N Nate ·2026-10-26#3

Apply it generically with :target or a class on all anchor targets. And use dvh aware heights if your header changes size on mobile.

⚑ Report
Log in to reply.