CSS scroll-padding-top Property

The CSS scroll-padding-top property defines an inset from the physical top edge of a scroll container's scrollport for scroll alignment.

This property adjusts the optimal viewing region used during scroll snapping and other scrolling operations. It is particularly useful for keeping headings, sections, and other scroll targets visible below fixed or sticky headers without changing their normal layout positions.

scroll-padding-top Syntax

The scroll-padding-top property accepts one non-negative CSS length, percentage, or the auto keyword.

Basic Syntax

selector {
  scroll-padding-top: 60px;
}

Available Values

.container {
  scroll-padding-top: 0;
}
.container {
  scroll-padding-top: 20px;
}
.container {
  scroll-padding-top: 4rem;
}
.container {
  scroll-padding-top: 2em;
}
.container {
  scroll-padding-top: 10%;
}
.container {
  scroll-padding-top: auto;
}
.container {
  scroll-padding-top: calc(60px + 1rem);
}

CSS-Wide Keywords

.container {
  scroll-padding-top: initial;
}
.container {
  scroll-padding-top: inherit;
}
.container {
  scroll-padding-top: unset;
}
.container {
  scroll-padding-top: revert;
}
.container {
  scroll-padding-top: revert-layer;
}

Negative values are invalid. Because this property controls a single physical edge, it accepts only one value.

Property Values

Value Description
<length> Sets a non-negative top inset using a CSS length such as px, rem, or em.
<percentage> Sets the top inset relative to the scrollport's height.
auto Allows the browser to determine an appropriate inset, typically zero.
0 Specifies no additional top scroll padding.
calc() Calculates a non-negative length or percentage-based inset.
initial Resets the property to its initial value of auto.
inherit Uses the computed value from the parent element.
unset Resets the property to auto because it is not inherited.
revert Reverts the property according to CSS cascade origin rules.
revert-layer Reverts the property according to CSS cascade layer rules.

Property Characteristics

Characteristic Value
Initial value auto
Inherited No
Applies to Scroll containers
Computed value As specified
Animation type By computed value type
Percentages Relative to the scrollport's height
Negative values Not accepted
Physical edge Top
Shorthand scroll-padding

Valid Values

.container {
  scroll-padding-top: 70px;
}
.container {
  scroll-padding-top: 15%;
}
.container {
  scroll-padding-top: 5rem;
}
.container {
  scroll-padding-top: auto;
}
.container {
  scroll-padding-top: calc(4rem + 12px);
}

Invalid Values

.container {
  scroll-padding-top: -20px;
}
.container {
  scroll-padding-top: 10px 20px;
}
.container {
  scroll-padding-top: smooth;
}
.container {
  scroll-padding-top: normal;
}
.container {
  scroll-padding-top: 2s;
}

Negative lengths, multiple values, unrelated keywords, and time units are invalid.

How It Works

The scroll-padding-top property establishes an inset from the physical top edge of a scrollport. The browser uses this inset when determining the optimal viewing region for scroll alignment.

For top-aligned targets, the browser can position content below the top boundary instead of directly against it.

Default Top Scroll Padding

.container {
  scroll-padding-top: auto;
}

The browser determines the inset. In most cases, the effective value is zero.

Fixed Top Inset

.container {
  scroll-padding-top: 80px;
}

The optimal viewing region begins 80 pixels below the physical top edge.

Percentage-Based Inset

.container {
  scroll-padding-top: 10%;
}

The inset is calculated as 10% of the scrollport's height. For example, a 400-pixel-tall scrollport produces a 40-pixel inset.

Relative Lengths

.container {
  scroll-padding-top: 4rem;
}

Relative units can help the inset scale with font-size settings.

No Layout Changes

Scroll padding does not create physical space or move elements in normal document flow. Unlike padding-top, it affects scroll alignment rather than layout spacing.

Available Scroll Range

The browser may not achieve the requested alignment if the scroll container does not have enough available scroll range.

Fixed and Sticky Headers

One common use of scroll-padding-top is preventing headings and other scroll targets from being obscured by a fixed or sticky header.

Fixed Page Header

html {
  scroll-padding-top: 80px;
}
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 80px;
}

When the document scrolls to a heading or another target, the 80-pixel inset provides room for the fixed header.

Sticky Header Inside a Scroll Container

.content-panel {
  height: 350px;
  overflow-y: auto;
  scroll-padding-top: 60px;
}
.content-panel .sticky-header {
  position: sticky;
  top: 0;
  height: 60px;
  z-index: 1;
}

The scroll container uses a 60-pixel top inset to account for its sticky header.

Responsive Header Heights

html {
  scroll-padding-top: 60px;
}
@media (min-width: 768px) {
  html {
    scroll-padding-top: 90px;
  }
}

The scroll alignment inset changes with the header height at different viewport widths.

Using a CSS Custom Property

:root {
  --header-height: 80px;
}
html {
  scroll-padding-top: var(--header-height);
}
.site-header {
  height: var(--header-height);
}

A shared custom property helps keep the header height and scroll alignment inset consistent.

Important Consideration

Scroll padding does not automatically detect the height of an overlapping header. Set an appropriate value and update it if the header height changes.

Using scroll-padding-top With Scroll Snap

The scroll-padding-top property is useful when vertically scrolling content should snap below the top edge of a container.

Vertical Scroll Snap

.scroll-container {
  height: 350px;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scroll-padding-top: 60px;
}
.scroll-container .section {
  min-height: 250px;
  scroll-snap-align: start;
}

In horizontal writing with normal top-to-bottom block progression, sections can snap 60 pixels below the top edge.

Different Top and Bottom Insets

.scroll-container {
  scroll-padding-top: 70px;
  scroll-padding-bottom: 20px;
}

The optimal viewing region begins 70 pixels below the top edge and ends 20 pixels above the bottom edge.

Start Alignment

.scroll-container {
  scroll-padding-top: 50px;
}
.scroll-container .section {
  scroll-snap-align: start;
}

In horizontal writing, start-aligned sections can snap inward from the top edge.

Combining Scroll Padding and Scroll Margin

.scroll-container {
  scroll-padding-top: 50px;
}
.scroll-container .featured {
  scroll-margin-top: 20px;
  scroll-snap-align: start;
}

For vertical start alignment in horizontal writing, these values can produce a combined 70-pixel offset between the featured section's top border edge and the scrollport's top edge.

Important Consideration

Scroll padding does not enable snapping by itself. The container requires scroll-snap-type, and targets require scroll-snap-align.

Anchor Navigation

Anchor links allow users to jump to sections within a document. The scroll-padding-top property can help prevent the destination heading from appearing beneath a fixed header.

Basic Anchor Links

<nav aria-label="Page sections">
  <a href="#overview">Overview</a>
  <a href="#examples">Examples</a>
  <a href="#resources">Resources</a>
</nav>
<section id="overview">
  <h2>Overview</h2>
</section>
<section id="examples">
  <h2>Examples</h2>
</section>
<section id="resources">
  <h2>Resources</h2>
</section>

Adding Top Scroll Padding

html {
  scroll-padding-top: 80px;
}

When a user follows an anchor link, the destination can align below the top inset instead of directly against the viewport edge.

Smooth Anchor Scrolling

html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
}
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

The top inset controls alignment, while scroll-behavior controls whether supported scrolling operations animate.

Scrolling Inside an Element

.article-panel {
  height: 400px;
  overflow-y: auto;
  scroll-padding-top: 50px;
}

Apply the property to the element that actually scrolls. For document viewport scrolling, the root element is the usual choice.

Important Consideration

Scroll padding changes alignment rather than the destination of an anchor link. The target's ID and the link's fragment identifier must still match.

Programmatic Scrolling

JavaScript scrolling methods can use the optimal viewing region established by scroll-padding-top when aligning a target.

Using scrollIntoView()

.scroll-container {
  scroll-padding-top: 80px;
}
document.querySelector(".target").scrollIntoView({
  behavior: "smooth",
  block: "start",
  inline: "nearest"
});

In horizontal writing with normal top-to-bottom block progression, the target can align approximately 80 pixels below the top edge, provided sufficient scroll range is available.

Using Nearest Alignment

document.querySelector(".target").scrollIntoView({
  behavior: "smooth",
  block: "nearest",
  inline: "nearest"
});

Nearest alignment minimizes scrolling rather than forcing top alignment, so the resulting position may differ.

Respecting Reduced Motion

const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
document.querySelector(".target").scrollIntoView({
  behavior: reduceMotion ? "instant" : "smooth",
  block: "start",
  inline: "nearest"
});

Consider reduced-motion preferences when using animated scrolling.

scrollTo() Versus scrollIntoView()

document.querySelector(".scroll-container").scrollTo({
  top: 200,
  behavior: "smooth"
});

The scrollTo() method scrolls to a specified coordinate rather than aligning a target within the optimal viewing region. Do not assume that scroll-padding-top will automatically be added to the requested coordinate.

Important Consideration

The block option uses logical alignment. In vertical writing modes, block: "start" may refer to the right or left edge instead of the top. The scroll-padding-top property always refers to the physical top edge.

Using the scroll-padding Shorthand

The scroll-padding shorthand sets scroll padding for all four physical edges of a scroll container.

One Value

.container {
  scroll-padding: 30px;
}

All four edges receive 30 pixels.

Two Values

.container {
  scroll-padding: 60px 20px;
}

The top and bottom edges receive 60 pixels, while the left and right edges receive 20 pixels.

Three Values

.container {
  scroll-padding: 60px 20px 30px;
}

Top receives 60 pixels, left and right receive 20 pixels, and bottom receives 30 pixels.

Four Values

.container {
  scroll-padding: 60px 20px 30px 40px;
}

The values apply clockwise: top 60 pixels, right 20 pixels, bottom 30 pixels, and left 40 pixels.

Equivalent Longhand Declarations

.container {
  scroll-padding-top: 60px;
  scroll-padding-right: 20px;
  scroll-padding-bottom: 30px;
  scroll-padding-left: 40px;
}

Overriding the Top Edge

.container {
  scroll-padding: 20px;
  scroll-padding-top: 80px;
}

The top inset becomes 80 pixels, while the other three edges remain at 20 pixels.

Declaration Order

.container {
  scroll-padding-top: 80px;
  scroll-padding: 20px;
}

The later shorthand resets the top inset to 20 pixels along with the other three edges.

Logical Versus Physical Scroll Padding

Physical scroll padding always refers to fixed edges. Logical scroll padding follows the writing mode and text direction.

Property Edge
scroll-padding-top Physical top
scroll-padding-right Physical right
scroll-padding-bottom Physical bottom
scroll-padding-left Physical left
scroll-padding-block-start Logical block-start
scroll-padding-block-end Logical block-end
scroll-padding-inline-start Logical inline-start
scroll-padding-inline-end Logical inline-end

Physical Top Inset

.container {
  scroll-padding-top: 50px;
}

The inset always applies to the physical top edge, regardless of writing mode or direction.

Logical Block-Start Inset

.container {
  scroll-padding-block-start: 50px;
}

In horizontal writing, block-start corresponds to the top edge. In vertical writing, it corresponds to the right or left edge.

Physical Edge Mapping

Writing Mode Direction Logical Equivalent of Top
horizontal-tb ltr or rtl block-start
vertical-rl ltr inline-start
vertical-rl rtl inline-end
vertical-lr ltr inline-start
vertical-lr rtl inline-end

Overlapping Declarations

.container {
  writing-mode: horizontal-tb;
  scroll-padding-top: 20px;
  scroll-padding-block-start: 60px;
}

In horizontal writing, both declarations affect the top edge. With equal specificity and importance, the later declaration takes precedence.

Choosing the Appropriate Property

Use scroll-padding-top when the inset must remain on the physical top edge. Use a logical property when the inset should follow the writing mode or text direction.

scroll-padding-top Versus scroll-margin-top

Both properties influence scroll alignment at the top edge, but they apply to different elements.

Property Applied To Purpose
scroll-padding-top Scroll container Defines an inset from the top edge of the optimal viewing region.
scroll-margin-top Scroll target Expands or contracts the target's scroll alignment area at its top edge.

Container-Side Scroll Padding

.scroll-container {
  scroll-padding-top: 60px;
}

The container provides a consistent top alignment inset for its scroll targets.

Target-Side Scroll Margin

.scroll-container .featured {
  scroll-margin-top: 20px;
}

The featured target receives additional top-side scroll alignment space.

Combining Both Properties

.scroll-container {
  scroll-padding-top: 60px;
}
.scroll-container .featured {
  scroll-margin-top: 20px;
  scroll-snap-align: start;
}

For vertical start alignment in horizontal writing, these values can produce a combined 80-pixel offset between the target's top border edge and the scrollport's top edge.

Choosing Between Them

Use scroll-padding-top when the entire scroll container needs a consistent top alignment inset. Use scroll-margin-top when individual headings or sections need different offsets.

Important Difference

Scroll padding accepts percentages and auto but not negative values. Scroll margin accepts negative lengths but not percentages or auto.

scroll-padding-top Example

This interactive example compares two vertically scrolling panels. The second panel uses scroll-padding-top: 60px to align the selected target farther below the top edge.

HTML Example

<div class="scroll-top-demo">
  <div class="scroll-example">
    <h3>Without Scroll Padding</h3>
    <div class="scroll-panel">
      <div class="item">Item 1</div>
      <div class="item">Item 2</div>
      <div class="item target">Target</div>
      <div class="item">Item 4</div>
      <div class="item">Item 5</div>
      <div class="item">Item 6</div>
    </div>
    <button type="button">Scroll to Target</button>
  </div>
  <div class="scroll-example with-padding">
    <h3>With Top Scroll Padding</h3>
    <div class="scroll-panel">
      <div class="item">Item 1</div>
      <div class="item">Item 2</div>
      <div class="item target">Target</div>
      <div class="item">Item 4</div>
      <div class="item">Item 5</div>
      <div class="item">Item 6</div>
    </div>
    <button type="button">Scroll to Target</button>
  </div>
</div>

CSS Example

.scroll-top-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 20px;
}
.scroll-top-demo .scroll-panel {
  height: 180px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid #cbd5e1;
  background-color: #f8fafc;
  scroll-snap-type: y mandatory;
}
.scroll-top-demo .item {
  min-height: 65px;
  margin-bottom: 10px;
  padding: 20px 10px;
  text-align: center;
  background-color: #e2e8f0;
  scroll-snap-align: start;
}
.scroll-top-demo .target {
  background-color: #bfdbfe;
  border: 2px solid #2563eb;
}
.scroll-top-demo .with-padding .scroll-panel {
  scroll-padding-top: 60px;
}
.scroll-top-demo button {
  margin-top: 10px;
  padding: 8px 12px;
  cursor: pointer;
}

JavaScript Example

document.querySelectorAll(".scroll-top-demo .scroll-example").forEach((example) => {
  const button = example.querySelector("button");
  const target = example.querySelector(".target");
  button.addEventListener("click", () => {
    target.scrollIntoView({
      behavior: window.matchMedia("(prefers-reduced-motion: reduce)").matches ? "instant" : "smooth",
      block: "start",
      inline: "nearest"
    });
  });
});
Browser Result

Without Scroll Padding

Item 1
Item 2
Target
Item 4
Item 5
Item 6

With Top Scroll Padding

Item 1
Item 2
Target
Item 4
Item 5
Item 6

Click each button to bring the target toward the top of its scroll panel. In the second panel, the 60-pixel scroll padding moves the requested alignment inward from the top edge.

Increasing Top Scroll Padding

.scroll-top-demo .with-padding .scroll-panel {
  scroll-padding-top: 80px;
}

The top alignment inset increases to 80 pixels.

Removing Top Scroll Padding

.scroll-top-demo .with-padding .scroll-panel {
  scroll-padding-top: 0;
}

The additional top alignment inset is removed.

Browser Compatibility Note

The final position depends on available scroll range and scroll snapping behavior. Targets near the beginning or end of the container may not reach the requested alignment.

Accessibility Considerations

Top scroll padding can improve the visibility of headings and focused content when fixed or sticky interface elements occupy the upper part of a scrolling area.

Avoid Obscured Headings

Use an appropriate top inset to help prevent anchor destinations from being hidden beneath a fixed header.

Maintain Keyboard Accessibility

Ensure navigation links and scrolling controls are keyboard accessible and have visible focus indicators.

Consider Focus Management

Calling scrollIntoView() does not automatically move keyboard focus. Scripted navigation may require additional focus handling.

Respect Reduced Motion Preferences

The property does not animate scrolling. If smooth scrolling is used, respect prefers-reduced-motion.

Account for Responsive Headers

Ensure the top inset remains appropriate when header height changes due to viewport size, text scaling, or responsive navigation.

Test Browser Zoom

Verify that scroll targets remain visible when users increase browser zoom or text size.

Common Mistakes

Using Negative Values

.container {
  scroll-padding-top: -20px;
}

Negative values are invalid.

Providing Multiple Values

.container {
  scroll-padding-top: 10px 20px;
}

This longhand property accepts only one value.

Applying the Property to the Wrong Element

Apply scroll-padding-top to the scroll container. For viewport scrolling, the root element is generally the appropriate target.

Confusing Scroll Padding With Layout Padding

scroll-padding-top affects scroll alignment, while padding-top adds normal layout spacing.

Confusing Scroll Padding With Scroll Margin

Scroll padding belongs on the container. Scroll margin belongs on the target.

Expecting Automatic Scroll Snapping

The property does not enable scroll snapping by itself.

Ignoring Declaration Order

A later scroll-padding shorthand can override an earlier scroll-padding-top declaration.

Assuming Top Always Means Block-Start

The top edge corresponds to block-start in horizontal writing, but it can correspond to inline-start or inline-end in vertical writing.

Using an Incorrect Header Height

A top inset that is smaller than an overlapping header may leave scroll targets partially obscured.

Ignoring Available Scroll Range

The browser may not achieve the requested alignment when the container cannot scroll far enough.

Expecting Extra Content Space

Scroll padding does not extend the scrollable content area. Additional layout spacing may be necessary for targets near the beginning or end of the content.

Important Considerations

Keep the following points in mind when using scroll-padding-top:

  • It defines a scroll alignment inset at the physical top edge.
  • It is a longhand of scroll-padding.
  • Its initial value is auto, and it is not inherited.
  • It accepts one non-negative length, percentage, or auto value.
  • Negative values are invalid.
  • Percentages are relative to the scrollport's height.
  • The affected edge remains top regardless of writing mode or direction.
  • It does not change normal layout spacing or element dimensions.
  • It can influence scroll snapping, anchor navigation, and programmatic scrolling.
  • It is useful for fixed headers, sticky headers, and vertically scrolling panels.
  • It does not create a scroll container or enable scroll snapping.
  • Use scroll-padding-bottom for the opposite physical edge.
  • Use scroll-padding-block-start when the inset should follow the logical block-start edge.
  • Use scroll-margin-top when individual targets need a top-side alignment offset.
  • Available scroll range may limit the final alignment position.
  • Test scrolling behavior across viewport sizes, writing modes, and browser zoom levels.

Browser Support

The CSS scroll-padding-top property is widely supported in current versions of major browsers, including Chrome, Edge, Firefox, and Safari.

Support in older browsers may be limited. Scroll alignment behavior can also vary depending on the scrolling operation and available scroll range.

For current compatibility information, visit Can I Use? and search for scroll-padding-top.

When unsupported, scrolling generally remains functional, but the requested top alignment inset may not be applied.

Specifications

The scroll-padding-top property is defined in CSS Scroll Snap Module Level 1.

CSS Scroll Snap Module Level 1

The specification defines how scroll padding establishes the optimal viewing region within a scrollport.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: scroll-padding-top