data-sticky
Make header or footer elements stick to the viewport edge on scroll. CSS-only — no JavaScript required.
Overview
Add data-sticky to a <header> or <footer> element to pin it to the viewport edge as the user scrolls. Headers stick to the top; footers stick to the bottom.
This is a CSS-only attribute — no JavaScript required. It sets position: sticky, z-index: 100, and background: var(--color-surface) to ensure the element stays visible above scrolling content.
Usage
Sticky Header
Pin a site header to the top of the viewport:
Sticky Footer
Pin a footer to the bottom of the viewport:
Supported Elements
| Element | Sticks to | CSS Applied |
|---|---|---|
<header data-sticky> |
Top of viewport | position: sticky; inset-block-start: 0 |
<footer data-sticky> |
Bottom of viewport | position: sticky; inset-block-end: 0 |
Backdrop Blur Enhancement
For a polished effect, add backdrop blur so content is visible behind the sticky header:
Accessibility
- Sticky headers should not obscure focused content when users navigate with keyboard
- Ensure sufficient contrast between the sticky element and page content scrolling beneath
- Consider
scroll-padding-topon the scroll container to offset anchor links below the sticky header
Related
<header>— Element that supports data-sticky for top positioning<footer>— Element that supports data-sticky for bottom positioning<table>— Usesdata-sticky="header|column|both"for sticky rows and columns (different attribute)- Navbar patterns — Sticky header recipes with backdrop blur