# scroll-padding

> The `scroll-padding` CSS property sets offsets of a scroll container's viewing area, so snapped content isn't hidden by fixed headers or footers.

## How do I stop a sticky header from covering anchor link targets?

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.

- Topic: Client Interface
- Type: property
- Browser support: Chrome 69+, Chrome Android 69+, Edge 79+, Firefox 68+, Firefox Android 68+, Safari 14.1+, Safari iOS 14.5+

## Example

Wrong:

```css
section:target {
  padding-top: 80px;
  margin-top: -80px;
}
```

Right:

```css
: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`.

## Related cards

- [scroll-snap-type](https://wonderium.dev/css/scroll-snap-type.md)
- [scroll-behavior](https://wonderium.dev/css/scroll-behavior.md)
- [position](https://wonderium.dev/css/position.md)
- [.scrollIntoView()](https://wonderium.dev/js/scroll-into-view.md)
- [:target](https://wonderium.dev/css/target.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/scroll-padding
- Last updated: 2026-11-25
