CSS scroll-padding-block Property
The CSS scroll-padding-block property is a logical shorthand that sets scroll alignment insets at the block-start and block-end edges of a scroll container.
Unlike physical scroll padding properties, these insets follow the element's writing mode. They help define the optimal viewing region for scroll snapping, anchor navigation, and programmatic scrolling without changing normal layout spacing.
scroll-padding-block Syntax
The scroll-padding-block property accepts one or two values. Each value can be a non-negative CSS length, a percentage, or auto.
Basic Syntax
selector {
scroll-padding-block: 20px;
}
One-Value Syntax
.container {
scroll-padding-block: 30px;
}
The same value applies to both block-start and block-end.
Two-Value Syntax
.container {
scroll-padding-block: 60px 20px;
}
The first value sets block-start, and the second sets block-end.
Other Valid Values
.container {
scroll-padding-block: auto;
}
.container {
scroll-padding-block: 5% 10%;
}
.container {
scroll-padding-block: 2rem 1rem;
}
.container {
scroll-padding-block: calc(3rem + 10px) 20px;
}
.container {
scroll-padding-block: 80px auto;
}
CSS-Wide Keywords
.container {
scroll-padding-block: initial;
}
.container {
scroll-padding-block: inherit;
}
.container {
scroll-padding-block: unset;
}
.container {
scroll-padding-block: revert;
}
.container {
scroll-padding-block: revert-layer;
}
Negative values are invalid. The auto keyword allows the browser to determine an appropriate scroll padding value.
Property Values
| Value | Description |
|---|---|
<length> |
Sets the scroll padding using a non-negative CSS length such as px, rem, or em. |
<percentage> |
Sets the scroll padding as a percentage of the scrollport's dimension along the block axis. |
auto |
Lets the browser determine the inset. It generally resolves to zero unless another offset is appropriate. |
0 |
Applies no additional scroll padding at the specified logical edges. |
calc() |
Calculates a valid non-negative length or percentage-based value. |
initial |
Resets both longhands to their initial value of auto. |
inherit |
Inherits the computed values of both longhands from the parent element. |
unset |
Resets both longhands to auto because they are not inherited. |
revert |
Reverts the longhands according to CSS cascade origin rules. |
revert-layer |
Reverts the longhands according to CSS cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | auto for both longhands |
| Inherited | No |
| Applies to | Scroll containers |
| Computed value | As specified for the individual longhands |
| Animation type | By computed value type for the individual longhands |
| Percentages | Relative to the scrollport's block-axis dimension |
| Negative values | Not accepted |
| Longhands | scroll-padding-block-start and scroll-padding-block-end |
Valid Values
.container {
scroll-padding-block: 40px;
}
.container {
scroll-padding-block: 10% 5%;
}
.container {
scroll-padding-block: 4rem 2rem;
}
.container {
scroll-padding-block: auto;
}
.container {
scroll-padding-block: calc(3rem + 10px) 20px;
}
Invalid Values
.container {
scroll-padding-block: -10px;
}
.container {
scroll-padding-block: 10px 20px 30px;
}
.container {
scroll-padding-block: smooth;
}
.container {
scroll-padding-block: 2s;
}
.container {
scroll-padding-block: normal;
}
The shorthand accepts a maximum of two non-negative length, percentage, or auto values. Scrolling behavior keywords and time units are invalid.
How It Works
The scroll-padding-block property defines insets from the block-start and block-end edges of a scroll container's scrollport.
These insets establish the optimal viewing region used when the browser aligns scroll targets.
Default Scroll Padding
.container {
scroll-padding-block: auto;
}
The browser determines the insets. In most cases, the effective values are zero.
Equal Block Insets
.container {
scroll-padding-block: 30px;
}
Both block-start and block-end receive 30 pixels of scroll padding.
Different Block Insets
.container {
scroll-padding-block: 80px 20px;
}
The block-start inset is 80 pixels, while the block-end inset is 20 pixels.
Percentage-Based Insets
.container {
scroll-padding-block: 10% 5%;
}
The percentages are calculated relative to the scrollport's dimension along the block axis.
No Layout Changes
Unlike regular padding-block, scroll padding does not add physical space inside the element or alter its box dimensions.
Available Scroll Range
The browser may not achieve the full requested offset if the scroll container cannot scroll far enough.
Writing Modes and Logical Edges
The main advantage of scroll-padding-block is that its edges follow the writing mode rather than fixed physical directions.
Logical Edge Mapping
| Writing Mode | Block-Start | Block-End |
|---|---|---|
horizontal-tb |
Top | Bottom |
vertical-rl |
Right | Left |
vertical-lr |
Left | Right |
sideways-rl |
Right | Left |
sideways-lr |
Left | Right |
Horizontal Writing Mode
.container {
writing-mode: horizontal-tb;
scroll-padding-block: 60px 20px;
}
The block-start inset applies to the top, and the block-end inset applies to the bottom.
Vertical Right-to-Left Writing Mode
.container {
writing-mode: vertical-rl;
scroll-padding-block: 60px 20px;
}
The block-start inset applies to the right, and the block-end inset applies to the left.
Vertical Left-to-Right Writing Mode
.container {
writing-mode: vertical-lr;
scroll-padding-block: 60px 20px;
}
The block-start inset applies to the left, and the block-end inset applies to the right.
Text Direction
Changing direction between ltr and rtl affects the inline axis, but it does not reverse the block-start and block-end edges in these writing modes.
Why Logical Properties Matter
Logical properties help the same CSS adapt to different writing systems without manually changing top, bottom, left, or right declarations.
One and Two Shorthand Values
The scroll-padding-block shorthand controls two logical edges.
One Value
.container {
scroll-padding-block: 30px;
}
Both block-start and block-end receive 30 pixels.
Two Values
.container {
scroll-padding-block: 80px 20px;
}
Block-start receives 80 pixels, and block-end receives 20 pixels.
Equivalent Longhand Declarations
.container {
scroll-padding-block-start: 80px;
scroll-padding-block-end: 20px;
}
Mixing Values
.container {
scroll-padding-block: 10% auto;
}
The block-start inset uses 10% of the scrollport's block-axis dimension, while block-end uses the browser-determined value.
Overriding One Edge
.container {
scroll-padding-block: 20px;
scroll-padding-block-start: 80px;
}
Block-start becomes 80 pixels, while block-end remains 20 pixels.
Declaration Order
.container {
scroll-padding-block-start: 80px;
scroll-padding-block: 20px;
}
The later shorthand resets both logical block insets to 20 pixels.
Combining With Inline Scroll Padding
.container {
scroll-padding-block: 60px 20px;
scroll-padding-inline: 30px;
}
The block axis receives different start and end values, while both inline edges receive 30 pixels.
Using scroll-padding-block With Scroll Snap
Scroll padding is useful when items should align within a specific region of a scrolling container rather than directly against its edges.
Vertical Scroll Snap
.scroll-container {
height: 300px;
overflow-y: auto;
scroll-snap-type: y mandatory;
scroll-padding-block: 40px 20px;
}
.scroll-container .item {
min-height: 200px;
scroll-snap-align: start;
}
In horizontal writing, the scroll container uses a 40-pixel top inset and a 20-pixel bottom inset.
Vertical Writing Mode
.scroll-container {
writing-mode: vertical-rl;
width: 300px;
overflow-x: auto;
scroll-snap-type: x mandatory;
scroll-padding-block: 40px 20px;
}
.scroll-container .item {
scroll-snap-align: start;
}
With vertical-rl, the block axis runs horizontally from right to left. The logical scroll padding therefore applies to the right and left edges.
Combining With Scroll Margin
.scroll-container {
scroll-padding-block-start: 30px;
}
.scroll-container .item {
scroll-margin-block-start: 20px;
}
For start alignment, these values can provide a combined 50-pixel offset between the item's block-start border edge and the scrollport's block-start edge.
Important Consideration
The property does not enable scroll snapping. The container still needs scroll-snap-type, and the targets need scroll-snap-align.
Anchor Navigation and Sticky Headers
In horizontal writing, scroll-padding-block-start can provide space above anchor targets so they remain visible beneath a sticky or fixed header.
Document Scroll Offset
html {
scroll-padding-block-start: 80px;
}
For a document using horizontal-tb, this creates a top scroll alignment inset of 80 pixels.
Using the Shorthand
html {
scroll-padding-block: 80px 20px;
}
The document receives an 80-pixel block-start inset and a 20-pixel block-end inset.
HTML Anchor Navigation
<nav aria-label="Page sections">
<a href="#overview">Overview</a>
<a href="#features">Features</a>
<a href="#contact">Contact</a>
</nav>
<section id="overview">
<h2>Overview</h2>
</section>
<section id="features">
<h2>Features</h2>
</section>
<section id="contact">
<h2>Contact</h2>
</section>
Using a Custom Property
:root {
--header-height: 80px;
}
html {
scroll-padding-block-start: calc(var(--header-height) + 16px);
}
The calculated inset accounts for the header height and adds 16 pixels of extra space.
Responsive Header Heights
html {
scroll-padding-block-start: 90px;
}
@media (max-width: 767px) {
html {
scroll-padding-block-start: 60px;
}
}
The scroll offset changes to accommodate a shorter header on smaller screens.
Important Consideration
For document scrolling, apply scroll padding to the root html element. For a separately scrolling panel, apply it to that panel's scroll container.
Logical Versus Physical Scroll Padding
The logical scroll-padding-block shorthand adapts to writing mode, while physical scroll padding properties always refer to fixed edges.
| Property | Edges |
|---|---|
scroll-padding-block |
Logical block-start and block-end |
scroll-padding-inline |
Logical inline-start and inline-end |
scroll-padding |
All four physical edges |
scroll-padding-top |
Physical top |
scroll-padding-right |
Physical right |
scroll-padding-bottom |
Physical bottom |
scroll-padding-left |
Physical left |
Physical Scroll Padding
.container {
scroll-padding-top: 60px;
scroll-padding-bottom: 20px;
}
These offsets remain on the physical top and bottom edges regardless of writing mode.
Logical Scroll Padding
.container {
scroll-padding-block: 60px 20px;
}
The offsets follow block-start and block-end, which can map to top and bottom or right and left depending on writing mode.
Overlapping Declarations
.container {
writing-mode: horizontal-tb;
scroll-padding-top: 20px;
scroll-padding-block-start: 60px;
}
Both declarations affect the physical top edge in this writing mode. With equal specificity and importance, the later declaration takes precedence.
Choosing Between Logical and Physical Properties
Use logical scroll padding when offsets should adapt to writing mode. Use physical properties when a specific top, right, bottom, or left edge must remain unchanged.
scroll-padding-block Versus scroll-margin-block
Both properties affect scroll alignment along the logical block axis, but they are applied to different elements.
| Property | Applied To | Purpose |
|---|---|---|
scroll-padding-block |
Scroll container | Defines block-axis insets within the optimal viewing region. |
scroll-margin-block |
Scroll target | Expands or contracts the target's scroll alignment area along the block axis. |
Container-Side Scroll Padding
.scroll-container {
scroll-padding-block: 40px 20px;
}
The container establishes block-start and block-end alignment insets for its scroll targets.
Target-Side Scroll Margin
.scroll-container .featured {
scroll-margin-block: 20px;
}
The featured target receives additional alignment space along its logical block axis.
Combining Both Properties
.scroll-container {
scroll-padding-block-start: 30px;
}
.scroll-container .featured {
scroll-margin-block-start: 20px;
}
For block-start alignment, the combined offset can be 50 pixels when sufficient scroll range is available.
Important Difference
scroll-padding-block accepts percentages and auto but not negative values. scroll-margin-block accepts negative lengths but not percentages or auto.
scroll-padding-block Example
This interactive example compares two vertically scrolling panels using horizontal writing mode. The second panel applies a 50-pixel block-start inset and a 20-pixel block-end inset.
HTML Example
<div class="scroll-block-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 Block 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-block-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
gap: 20px;
}
.scroll-block-demo .scroll-panel {
height: 180px;
overflow-y: auto;
padding: 10px;
border: 1px solid #cbd5e1;
background-color: #f8fafc;
scroll-snap-type: y mandatory;
}
.scroll-block-demo .item {
padding: 22px 10px;
margin-bottom: 10px;
text-align: center;
background-color: #e2e8f0;
scroll-snap-align: start;
}
.scroll-block-demo .target {
background-color: #bfdbfe;
border: 2px solid #2563eb;
}
.scroll-block-demo .with-padding .scroll-panel {
scroll-padding-block: 50px 20px;
}
.scroll-block-demo button {
margin-top: 10px;
padding: 8px 12px;
cursor: pointer;
}
JavaScript Example
document.querySelectorAll(".scroll-block-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"
});
});
});
Without Scroll Padding
With Block Scroll Padding
Click each button to scroll its target toward the top of the panel. The second panel requests a 50-pixel block-start inset, which corresponds to the top edge in horizontal writing mode.
Increasing the Block-Start Offset
.scroll-block-demo .with-padding .scroll-panel {
scroll-padding-block: 80px 20px;
}
The block-start inset increases to 80 pixels.
Removing the Scroll Padding
.scroll-block-demo .with-padding .scroll-panel {
scroll-padding-block: 0;
}
Both logical block insets become zero.
Browser Compatibility Note
The final scroll position depends on available scroll range and scroll snapping behavior. Targets near the beginning or end of the container may not reach their requested alignment.
Accessibility Considerations
Logical scroll padding can help maintain visible scroll targets across different writing modes and interface layouts.
Keep Anchor Targets Visible
Use appropriate block-start scroll padding when sticky headers or other interface elements could obscure anchor-linked content.
Maintain Keyboard Accessibility
Scrolling controls should remain keyboard accessible and provide visible focus indicators.
Consider Focus Management
Programmatic scrolling 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.
Support Different Writing Modes
Logical scroll padding adapts to writing mode, making it useful for interfaces that support horizontal and vertical text layouts.
Test Responsive Layouts
Verify scroll alignment at different viewport sizes, browser zoom levels, and text scaling settings.
Common Mistakes
Using Negative Values
.container {
scroll-padding-block: -20px;
}
Negative values are invalid.
Providing Too Many Values
.container {
scroll-padding-block: 10px 20px 30px;
}
The shorthand accepts only one or two values.
Confusing Block With Vertical
The block axis is vertical in horizontal writing modes but horizontal in vertical writing modes.
Confusing Scroll Padding With Layout Padding
scroll-padding-block affects scroll alignment, while padding-block affects normal layout spacing.
Applying the Property to Scroll Targets
Apply scroll-padding-block to the scroll container. Use scroll-margin-block on individual targets.
Expecting Automatic Scroll Snapping
The property does not enable scroll snapping by itself.
Ignoring Declaration Order
A later scroll-padding-block declaration can override earlier block-start or block-end longhand values.
Ignoring Physical and Logical Conflicts
Physical and logical scroll padding declarations may affect the same edge. The CSS cascade determines which declaration applies.
Ignoring Available Scroll Range
Large insets may not produce the expected alignment if the container cannot scroll far enough.
Important Considerations
Keep the following points in mind when using scroll-padding-block:
- It is a logical shorthand for
scroll-padding-block-startandscroll-padding-block-end. - It accepts one or two values.
- One value applies to both block edges.
- Two values apply to block-start and block-end, respectively.
- Each value can be a non-negative length, percentage, or
auto. - The initial value of each longhand is
auto. - The property is not inherited.
- Negative values are invalid.
- Percentages are relative to the scrollport's block-axis dimension.
- Its physical edges depend on the writing mode.
- It defines scroll alignment insets without changing normal layout spacing.
- It can influence scroll snapping, anchor navigation, and programmatic scrolling.
- It does not create a scroll container or enable scroll snapping.
- Use
scroll-padding-inlinefor the logical inline axis. - Use
scroll-margin-blockwhen individual targets need block-axis alignment offsets. - Available scroll range may limit the final alignment position.
- Test scrolling behavior across writing modes, viewport sizes, and input methods.
Browser Support
The CSS scroll-padding-block property is supported in current versions of major browsers, including Chrome, Edge, Firefox, and Safari.
Support in older browsers may be limited, particularly for logical scroll padding properties and vertical writing modes.
For current compatibility information, visit Can I Use? and search for scroll-padding-block.
When unsupported, scrolling generally remains functional, but the requested logical alignment insets may not be applied.
Specifications
The scroll-padding-block property is defined in CSS Scroll Snap Module Level 1.
CSS Scroll Snap Module Level 1
The specification defines scroll padding insets and their relationship to the scrollport's optimal viewing region.
For additional documentation and examples, consult MDN Web Docs.
