scroll-padding

Term side of the Card.
Topic: Client Interface
Unit title: scroll-padding
Categories: Property
Explanation side of the Card

Explanation: The property of a scroll container that offsets where content lands after scroll snapping, anchor jumps or `scrollIntoView()`. It adds no visible space, and is often set to the height of a sticky header so targets aren't hidden under it.

Browser compatibility:
  • The chrome browser supports this feature starting from version 69.
  • The edge browser supports this feature starting from version 79.
  • The firefox browser supports this feature starting from version 68.
  • The safari browser supports this feature starting from version 14.1.
Availability: 

Example

Wrongcss
section:target {
  padding-top: 80px;
  margin-top: -80px;
}
Rightcss
:root {
  --header-h: 80px;
}

html {
  scroll-padding-top: var(--header-h);
}

The scroll container now keeps the header height free, so every anchor target lands below the sticky header without margin hacks.

Common mistakes

  • Putting scroll-padding-top on the section instead of the scroll container.
  • The header height changes on mobile, but the hardcoded offset does not.

Key points

  • scroll-padding is set on the scroll container, like html, not on the target element.
  • The offset matches the sticky header height, ideally through a shared custom property.
  • Anchor offsets use scroll-padding instead of JavaScript that scrolls and subtracts the header height.

Interview questions

What is the difference between scroll-padding and scroll-margin?

scroll-padding goes on the scroll container and applies to all targets. scroll-margin goes on one target and adds space around only that element.

Does scroll-padding work with scrollIntoView()?

Yes. scrollIntoView(), anchor links and scroll snapping all respect scroll-padding on the scroll container.

Does scroll-padding add visible space to the layout?

No. It only changes where scrolled-to content stops; it does not move content or change the box size like padding.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy