Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ scroll-padding: unset;

{{Compat}}

## Examples
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire section needs to be moved above the "Specifications" section.


### Preventing content from being hidden by a fixed header

A common use case for `scroll-padding` is when a page includes a fixed-position header.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A common use case for `scroll-padding` is when a page includes a fixed-position header.
A common use case for `scroll-padding` is to prevent scrolling content from being hidden by a fixed-position header. This example demonstrates how to use `scroll-padding` for this purpose.

Without `scroll-padding`, content linked via fragment identifiers can be hidden beneath the header.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Without `scroll-padding`, content linked via fragment identifiers can be hidden beneath the header.


```css
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it stands, this doesn't really demonstrate the use case very clearly. Can you expand the example to show more complete code and a live example perhaps? It doesn't have to be as elaborate as this example, but this is the kind of pattern you should ideally follow: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/scroll-target-group#basic_scroll-target-group_usage.

header {
position: fixed;
top: 0;
height: 60px;
width: 100%;
}

html {
scroll-padding-top: 60px;
}
```

## See also

- [CSS scroll snap](/en-US/docs/Web/CSS/Guides/Scroll_snap)
Expand Down