CSS scroll-padding Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Scrolling

What You’ll Learn

The scroll-padding property insets the scroll snap area inside a scroll container. It is especially helpful for scroll snapping and page navigation when fixed headers or footers would otherwise hide snapped content at the container edges.

01

Container

Scrollport inset.

02

top

Clear fixed header.

03

length

px, rem, em.

04

snap

Vertical panels.

05

auto

Browser default.

06

margin

Companion prop.

Introduction

The scroll-padding property in CSS is used to define the offset around the edges of a scroll container where the browser will stop scrolling when a user performs a scroll snap or navigates to a scroll destination.

This property helps control the positioning of content when using scroll snapping, ensuring that desired elements are fully visible and not obscured by other UI elements like fixed headers or footers.

Definition and Usage

Apply scroll-padding to the scroll container — such as html, an element with overflow: auto, or the element that has scroll-snap-type set.

Unlike regular padding, scroll-padding does not shift layout content. It only changes the inset of the scrollport where snapping and scroll positioning occur.

💡
Beginner Tip

If snapped sections hide under a fixed header, add scroll-padding-top: 50px on the scroll container to match the header height.

📝 Syntax

The syntax for the scroll-padding property allows you to specify padding for one or more sides of the scroll container.

syntax.css
element {
  scroll-padding: length | percentage | auto;
}

Basic Example

scroll-padding-top.css
html {
  scroll-padding-top: 50px;
}

Longhand Properties

  • scroll-padding-top, scroll-padding-right, scroll-padding-bottom, scroll-padding-left
  • scroll-padding-block, scroll-padding-inline
  • scroll-padding-block-start, scroll-padding-block-end, scroll-padding-inline-start, scroll-padding-inline-end

Syntax Rules

  • One to four values work like regular padding shorthand.
  • Length units such as px, rem, and em are common.
  • Percentages are relative to the scroll container’s dimensions.
  • Set the inset on the scroll container, not on individual snap targets.

🎯 Default Value

The default value of the scroll-padding property is 0 for all sides, meaning no additional inset is applied to the scrollport by default.

⚡ Quick Reference

QuestionAnswer
Default value0
Fixed header fixscroll-padding-top: 50px;
Accepted valuesLengths, percentages, auto
Set onScroll containers
InheritedNo
AnimatableNo

💎 Property Values

ValueExampleDescription
lengthscroll-padding-top: 50px;Specifies a fixed inset in units such as px, em, rem, etc.
percentagescroll-padding-top: 10%;Specifies inset relative to the scroll container’s width or height.
autoscroll-padding: auto;Lets the browser calculate the padding.
scroll-padding-top 50px 4rem 24px 12px

When to Use scroll-padding

scroll-padding solves common scroll-position problems:

  • Fixed headers — Inset the scrollport so snapped sections are not hidden under a fixed nav bar.
  • Scroll snapping layouts — Improve full-page and in-container vertical or horizontal snap panels.
  • Carousel tracks — Add side inset so first and last slides do not feel cramped at the edges.
  • Nested scroll areas — Fine-tune snap stops inside modals, sidebars, and overflow boxes.

If you need to offset individual scroll targets instead, use scroll-margin on the target element.

👀 Live Preview

Scroll inside the box below. The container uses scroll-padding-top: 2.5rem so snapped panels stop below the demo header bar.

Fixed header bar (demo)

Panel 1

Snaps with top inset inside the scrollport.

Panel 2

Scroll to see the padding effect.

Panel 3

Each panel aligns below the inset area.

Without scroll-padding-top, snapped content would sit flush against the top of the scroll box.

Examples Gallery

Start with the reference fixed-header example, inset a page scrollport, try shorthand values, and use rem units to match header height.

📜 Scroll Containers

Inset the scrollport so snapped content is not hidden under fixed UI — matching the reference example.

Example 1 — scroll-padding-top with a fixed header

In this example, we’ll add scroll padding so content is not hidden under a fixed header during vertical scroll snapping.

index.html
<style>
  html {
    scroll-snap-type: y mandatory;
    scroll-padding-top: 50px;
  }

  header {
    position: fixed;
    top: 0;
    width: 100%;
    height: 50px;
    background: #334155;
    color: #fff;
  }

  section {
    height: 100vh;
    scroll-snap-align: start;
  }
</style>

<header>Fixed Header</header>
<section style="background:lightcoral">Section 1</section>
<section style="background:lightblue">Section 2</section>
Try It Yourself

How It Works

The scroll container’s snap area is inset from the top edge by 50px before the browser settles the scroll position.

Example 2 — Page scrollport with sticky navigation

Set scroll-padding-top on html so anchor jumps and snap scrolling respect a sticky nav height.

page-scroll.css
html {
  scroll-behavior: smooth;
  scroll-padding-top: 4rem;
}
Try It Yourself

How It Works

Because the scrollport is inset on the container, every scroll destination inside that container benefits from the same top offset.

🗃 Shorthand & Units

Use multiple sides and relative units when building responsive snap layouts.

Example 3 — scroll-padding shorthand on a snap container

Set vertical and horizontal insets with two values: scroll-padding: 24px 12px; on an overflow scroll box.

shorthand.css
.snap-box {
  overflow: auto;
  scroll-snap-type: y mandatory;
  scroll-padding: 24px 12px;
}
Try It Yourself

How It Works

Shorthand follows the same value order as regular padding.

Example 4 — rem units matching header height

Use scroll-padding-top: 3.5rem; when the fixed header height is defined in rem.

rem-inset.css
html {
  scroll-padding-top: 3.5rem;
}
Try It Yourself

How It Works

rem keeps the container inset proportional when users change default text size settings.

scroll-padding vs scroll-margin

scroll-padding insets the scrollport on the container. scroll-margin offsets individual scroll targets. Both can solve fixed-header overlap — choose based on whether you control the container or each target.

Pair with scroll-behavior: smooth on documentation pages for polished in-page navigation.

container-inset.css
html {
  scroll-behavior: smooth;
  scroll-padding-top: 4rem;
}

🧠 How scroll-padding Works

1

Scroll container is configured

A page or overflow box with scroll-padding defines inset edges for the scrollport.

Container
2

Scrollport edges inset

The browser shrinks the effective snap and scroll stop area away from the container edges.

Inset
3

Content snaps into place

Snapped items and scroll destinations land inside the padded scrollport instead of under fixed UI.

Position
=

Visible snap stops

Important content stays readable, even with fixed headers and footers.

Browser Compatibility

The scroll-padding property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.

Scrolling · Modern support

Reliable scroll-padding support

Current Chrome, Firefox, Safari, Edge, and Opera support scroll-padding on scroll containers.

97% Modern browser support
Google Chrome 69+ · Desktop & Mobile
Full support
Mozilla Firefox 68+ · Desktop & Mobile
Full support
Apple Safari 14.1+ · macOS & iOS
Full support
Microsoft Edge 79+ · Chromium
Full support
Opera 56+ · Modern versions
Full support

Testing tip

Test scroll snapping on mobile browsers to confirm the container inset clears your fixed header height.

scroll-padding property 97% supported

Bottom line: scroll-padding is widely available in modern browsers for scroll containers and snap layouts.

Conclusion

The scroll-padding property is a valuable tool for enhancing the user experience when using scroll snapping on your web pages.

By controlling the padding around the edges of a scroll container, you can ensure that important content is not hidden and that the layout remains visually appealing. Experiment with different padding values to see how this property can improve the usability and aesthetics of your web projects.

💡 Best Practices

✅ Do

  • Set scroll-padding-top on the scroll container to match fixed header height
  • Use it with scroll-snap-type for full-page snap layouts
  • Prefer rem when the header size is defined in rem
  • Pair with scroll-behavior: smooth for polished page navigation
  • Test snap panels inside nested overflow containers

❌ Don’t

  • Confuse scroll-padding with regular layout padding
  • Put scroll-padding on snap targets instead of the scroll container
  • Assume scroll-padding and scroll-margin are interchangeable
  • Use huge percentage values without testing on small screens
  • Forget to set padding on the element that actually scrolls

Key Takeaways

Knowledge Unlocked

Five things to remember about scroll-padding

Use these points when insetting scroll containers.

5
Core concepts
02

top

Header fix.

Pattern
03

container

Not target.

Scope
04

auto

Browser calc.

Values
🔄 05

margin

Target pair.

Companion

❓ Frequently Asked Questions

scroll-padding insets the scroll snap area inside a scroll container. It creates padding around the edges of the scrollport so snapped or scrolled content is not hidden under fixed headers or flush against container edges.
scroll-padding is set on the scroll container to inset the scrollport. scroll-margin is set on the target element being scrolled to. Both can solve header overlap, but at different levels.
Regular padding affects layout and shifts content inside the box. scroll-padding only changes where scrolling and scroll snapping stop relative to the container edges.
The default value is 0 on all sides, meaning no inset is applied to the scrollport.
Use scroll-padding-top on the scroll container when a fixed or sticky header would otherwise cover snapped sections or anchor destinations at the top of the viewport.

Practice in the Live Editor

Open the HTML editor and try scroll-padding-top: 50px on a scroll container with snap sections.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful