CSS scroll-padding-inline Property
The CSS scroll-padding-inline property sets scroll alignment insets at the inline-start and inline-end edges of a scroll container.
It is a logical shorthand property that adjusts the optimal viewing region used for scroll snapping and other scrolling operations. The physical edges depend on the writing mode and text direction, making it useful for horizontal carousels, right-to-left layouts, and vertical writing systems.
scroll-padding-inline Syntax
The scroll-padding-inline shorthand accepts one or two values. Each value must be a non-negative CSS length, percentage, or the auto keyword.
Basic Syntax
selector {
scroll-padding-inline: 20px;
}
One-Value Syntax
.container {
scroll-padding-inline: 30px;
}
Both inline-start and inline-end receive a 30-pixel inset.
Two-Value Syntax
.container {
scroll-padding-inline: 40px 20px;
}
The first value applies to inline-start, and the second applies to inline-end.
Additional Valid Values
.container {
scroll-padding-inline: 0;
}
.container {
scroll-padding-inline: 2rem;
}
.container {
scroll-padding-inline: 5% 10%;
}
.container {
scroll-padding-inline: auto;
}
.container {
scroll-padding-inline: 40px auto;
}
.container {
scroll-padding-inline: calc(2rem + 10px) 1rem;
}
CSS-Wide Keywords
.container {
scroll-padding-inline: initial;
}
.container {
scroll-padding-inline: inherit;
}
.container {
scroll-padding-inline: unset;
}
.container {
scroll-padding-inline: revert;
}
.container {
scroll-padding-inline: revert-layer;
}
Negative values are invalid. CSS-wide keywords must be used alone rather than combined with a second value.
Property Values
| Value | Description |
|---|---|
<length> |
Sets an inset using a non-negative CSS length such as px, rem, or em. |
<percentage> |
Sets an inset relative to the scrollport's dimension along the inline axis. |
auto |
Lets the browser determine an appropriate inset, typically zero. |
0 |
Specifies no additional scroll padding at the selected inline edges. |
calc() |
Calculates a valid non-negative length or percentage-based inset. |
initial |
Resets both longhand properties to their initial value of auto. |
inherit |
Inherits both longhand values from the parent element. |
unset |
Resets both longhand properties to auto because they are not inherited. |
revert |
Reverts both longhand properties according to CSS cascade origin rules. |
revert-layer |
Reverts both longhand properties according to CSS cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | auto for both longhands |
| Inherited | No |
| Applies to | Scroll containers |
| Computed value | See the individual longhand properties |
| Animation type | See the individual longhand properties |
| Percentages | Relative to the scrollport's inline-axis dimension |
| Negative values | Not accepted |
| Number of values | One or two |
| Longhands | scroll-padding-inline-start and scroll-padding-inline-end |
Valid Values
.container {
scroll-padding-inline: 20px;
}
.container {
scroll-padding-inline: 40px 15px;
}
.container {
scroll-padding-inline: 5% 10%;
}
.container {
scroll-padding-inline: auto 2rem;
}
.container {
scroll-padding-inline: calc(1rem + 8px);
}
Invalid Values
.container {
scroll-padding-inline: -20px;
}
.container {
scroll-padding-inline: 10px 20px 30px;
}
.container {
scroll-padding-inline: smooth;
}
.container {
scroll-padding-inline: normal;
}
.container {
scroll-padding-inline: 2s;
}
The shorthand accepts no more than two values. Negative lengths, scrolling behavior keywords, and unrelated units are invalid.
How It Works
The scroll-padding-inline property defines insets at both logical inline edges of a scroll container's scrollport.
These insets reduce the optimal viewing region used to align content during scrolling. They do not add layout padding or change the dimensions of the scroll container.
Equal Inline Insets
.container {
scroll-padding-inline: 40px;
}
The optimal viewing region begins 40 pixels inward from inline-start and ends 40 pixels before inline-end.
Different Inline Insets
.container {
scroll-padding-inline: 60px 20px;
}
The inline-start inset is 60 pixels, and the inline-end inset is 20 pixels.
Percentage-Based Insets
.container {
scroll-padding-inline: 10%;
}
In horizontal writing, both insets are calculated as 10% of the scrollport's width. In vertical writing, they are based on its height.
Automatic Insets
.container {
scroll-padding-inline: auto;
}
The browser determines both insets. In most cases, their effective values are zero.
No Layout Changes
Unlike padding-inline, scroll padding does not move child elements, change the container's box dimensions, or create additional content space.
Available Scroll Range
Scroll alignment may be limited near the beginning or end of the scrollable content. The browser cannot always achieve the requested inset.
Writing Modes and Text Direction
The physical edges controlled by scroll-padding-inline depend on the scroll container's writing-mode and direction properties.
Logical Edge Mapping
| Writing Mode | Direction | Inline-Start | Inline-End |
|---|---|---|---|
horizontal-tb |
ltr |
Left | Right |
horizontal-tb |
rtl |
Right | Left |
vertical-rl |
ltr |
Top | Bottom |
vertical-rl |
rtl |
Bottom | Top |
vertical-lr |
ltr |
Top | Bottom |
vertical-lr |
rtl |
Bottom | Top |
Left-to-Right Horizontal Writing
.container {
writing-mode: horizontal-tb;
direction: ltr;
scroll-padding-inline: 50px 20px;
}
The left inset is 50 pixels, and the right inset is 20 pixels.
Right-to-Left Horizontal Writing
.container {
writing-mode: horizontal-tb;
direction: rtl;
scroll-padding-inline: 50px 20px;
}
The right inset is 50 pixels, and the left inset is 20 pixels.
Vertical Writing
.container {
writing-mode: vertical-rl;
direction: ltr;
scroll-padding-inline: 50px 20px;
}
The top inset is 50 pixels, and the bottom inset is 20 pixels.
Why Logical Properties Matter
Logical scroll padding adapts to different writing systems without requiring separate left, right, top, and bottom declarations for every text direction.
Using scroll-padding-inline With Scroll Snap
The scroll-padding-inline property is especially useful for scroll snapping along the inline axis.
Horizontal Scroll Snap
.scroll-container {
display: flex;
gap: 16px;
overflow-x: auto;
scroll-snap-type: x mandatory;
scroll-padding-inline: 40px;
}
.scroll-container .item {
flex: 0 0 220px;
scroll-snap-align: start;
}
In left-to-right horizontal writing, items can snap 40 pixels inward from the left edge instead of aligning directly against it.
Different Start and End Insets
.scroll-container {
scroll-padding-inline: 60px 20px;
}
Start-aligned targets use the 60-pixel inline-start inset, while end-aligned targets use the 20-pixel inline-end inset.
End Alignment
.scroll-container {
scroll-padding-inline: 40px;
}
.scroll-container .item {
scroll-snap-align: end;
}
Items can align inward from the inline-end edge when snapping to the end position.
Center Alignment
.scroll-container {
scroll-padding-inline: 40px;
}
.scroll-container .item {
scroll-snap-align: center;
}
Equal insets preserve the center of the optimal viewing region. Unequal insets shift that region's center toward the side with the smaller inset.
Important Consideration
Scroll padding does not enable snapping by itself. The container requires scroll-snap-type, and targets require scroll-snap-align.
Horizontal Carousels
Horizontal carousels often need space between the viewport edges and the currently aligned item. The scroll-padding-inline property provides this alignment spacing without changing the items' layout positions.
Basic Carousel
.carousel {
display: flex;
gap: 16px;
overflow-x: auto;
scroll-snap-type: x mandatory;
scroll-padding-inline: 24px;
}
.carousel .slide {
flex: 0 0 250px;
scroll-snap-align: start;
}
Slides can snap 24 pixels inward from the inline-start edge.
Combining Layout Padding and Scroll Padding
.carousel {
display: flex;
gap: 16px;
overflow-x: auto;
padding-inline: 24px;
scroll-padding-inline: 24px;
scroll-snap-type: x mandatory;
}
Layout padding creates actual space at the carousel edges, while scroll padding establishes the intended snap alignment. Using both can help the first and last slides align consistently.
Responsive Carousel Insets
.carousel {
scroll-padding-inline: 16px;
}
@media (min-width: 768px) {
.carousel {
scroll-padding-inline: 40px;
}
}
The carousel uses smaller alignment insets on narrow screens and larger insets on wider screens.
Right-to-Left Carousels
.carousel {
direction: rtl;
scroll-padding-inline: 40px 20px;
}
In right-to-left horizontal writing, inline-start is the right edge. The 40-pixel inset therefore applies to the right, while 20 pixels applies to the left.
Important Consideration
Scroll padding does not guarantee extra scroll range at the beginning or end of a carousel. Layout padding or another appropriate spacing technique may be needed to make edge items align as intended.
Programmatic Scrolling
JavaScript scrolling methods can use the optimal viewing region defined by scroll-padding-inline when aligning a target along the inline axis.
Using scrollIntoView()
.scroll-container {
scroll-padding-inline: 40px;
}
document.querySelector(".target").scrollIntoView({
behavior: "smooth",
inline: "start",
block: "nearest"
});
In left-to-right horizontal writing, the target can align approximately 40 pixels inward from the left edge, provided sufficient scroll range is available.
Inline-End Alignment
document.querySelector(".target").scrollIntoView({
behavior: "smooth",
inline: "end",
block: "nearest"
});
This requests alignment with the inline-end edge of the optimal viewing region.
Inline-Center Alignment
document.querySelector(".target").scrollIntoView({
behavior: "smooth",
inline: "center",
block: "nearest"
});
The target is aligned toward the center of the optimal viewing region.
Respecting Reduced Motion
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
document.querySelector(".target").scrollIntoView({
behavior: reduceMotion ? "instant" : "smooth",
inline: "start",
block: "nearest"
});
Consider reduced-motion preferences when using animated scrolling.
Important Consideration
Scroll padding affects alignment, not scrolling speed, animation duration, or keyboard focus.
Inline-Start and Inline-End Longhands
The scroll-padding-inline shorthand controls two longhand properties:
scroll-padding-inline-start- defines the inline-start inset.scroll-padding-inline-end- defines the inline-end inset.
One-Value Shorthand
.container {
scroll-padding-inline: 30px;
}
This is equivalent to:
.container {
scroll-padding-inline-start: 30px;
scroll-padding-inline-end: 30px;
}
Two-Value Shorthand
.container {
scroll-padding-inline: 60px 20px;
}
This is equivalent to:
.container {
scroll-padding-inline-start: 60px;
scroll-padding-inline-end: 20px;
}
Overriding Inline-Start
.container {
scroll-padding-inline: 20px;
scroll-padding-inline-start: 60px;
}
The inline-start inset becomes 60 pixels, while inline-end remains 20 pixels.
Declaration Order
.container {
scroll-padding-inline-start: 60px;
scroll-padding-inline: 20px;
}
The later shorthand resets both inline insets to 20 pixels.
Combining Block and Inline Insets
.container {
scroll-padding-block: 40px 20px;
scroll-padding-inline: 60px 30px;
}
The block and inline axes can use different start and end alignment insets.
Logical Versus Physical Scroll Padding
Logical scroll padding follows the writing mode and text direction. Physical scroll padding always refers to fixed top, right, bottom, or left edges.
| Property | Edges |
|---|---|
scroll-padding-inline |
Logical inline-start and inline-end |
scroll-padding-block |
Logical block-start and block-end |
scroll-padding-left |
Physical left |
scroll-padding-right |
Physical right |
scroll-padding-top |
Physical top |
scroll-padding-bottom |
Physical bottom |
Physical Left and Right Insets
.container {
scroll-padding-left: 40px;
scroll-padding-right: 20px;
}
The insets remain on the left and right edges regardless of writing mode or text direction.
Logical Inline Insets
.container {
scroll-padding-inline: 40px 20px;
}
The first value follows inline-start, and the second follows inline-end.
Overlapping Declarations
.container {
direction: ltr;
scroll-padding-left: 20px;
scroll-padding-inline-start: 60px;
}
In left-to-right horizontal writing, both declarations affect the left edge. With equal specificity and importance, the later declaration takes precedence.
Choosing the Appropriate Property
Use logical properties for writing-mode-aware interfaces. Use physical properties when alignment must remain tied to a particular physical edge.
scroll-padding-inline Versus scroll-margin-inline
Both properties influence scroll alignment along the inline axis, but they apply to different elements.
| Property | Applied To | Purpose |
|---|---|---|
scroll-padding-inline |
Scroll container | Defines inline-start and inline-end insets for the optimal viewing region. |
scroll-margin-inline |
Scroll targets | Expands or contracts the targets' scroll alignment areas along the inline axis. |
Container-Side Scroll Padding
.scroll-container {
scroll-padding-inline: 40px;
}
Every target in the container uses the same inline alignment insets.
Target-Side Scroll Margin
.scroll-container .featured {
scroll-margin-inline: 20px;
}
The featured target receives additional scroll alignment space at both inline edges.
Combining Both Properties
.scroll-container {
scroll-padding-inline: 40px;
}
.scroll-container .featured {
scroll-margin-inline: 20px;
}
For start or end alignment, these values can create a combined 60-pixel offset between the target's corresponding border edge and the scrollport edge.
Important Difference
Scroll padding accepts percentages and auto but not negative values. Scroll margin accepts negative lengths but not percentages or auto.
scroll-padding-inline Example
This interactive example compares two horizontal scrolling panels. The second panel uses scroll-padding-inline: 40px so the selected target aligns farther from the inline-start edge.
HTML Example
<div class="scroll-inline-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 Inline 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-inline-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
gap: 20px;
}
.scroll-inline-demo .scroll-panel {
display: flex;
gap: 10px;
overflow-x: auto;
padding: 10px;
border: 1px solid #cbd5e1;
background-color: #f8fafc;
scroll-snap-type: x mandatory;
}
.scroll-inline-demo .item {
flex: 0 0 110px;
padding: 25px 10px;
text-align: center;
background-color: #e2e8f0;
scroll-snap-align: start;
}
.scroll-inline-demo .target {
background-color: #bfdbfe;
border: 2px solid #2563eb;
}
.scroll-inline-demo .with-padding .scroll-panel {
scroll-padding-inline: 40px;
}
.scroll-inline-demo button {
margin-top: 10px;
padding: 8px 12px;
cursor: pointer;
}
JavaScript Example
document.querySelectorAll(".scroll-inline-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",
inline: "start",
block: "nearest"
});
});
});
Without Scroll Padding
With Inline Scroll Padding
Click each button to bring the target toward the inline-start edge. In the second panel, the 40-pixel scroll padding moves the requested alignment inward from that edge.
Using Different Inline Insets
.scroll-inline-demo .with-padding .scroll-panel {
scroll-padding-inline: 60px 20px;
}
Inline-start receives 60 pixels, and inline-end receives 20 pixels.
Removing Inline Scroll Padding
.scroll-inline-demo .with-padding .scroll-panel {
scroll-padding-inline: 0;
}
The additional inline alignment insets are removed.
Browser Compatibility Note
The final scroll position depends on available scroll range, writing mode, and scroll snapping behavior. Targets near the beginning or end of the container may not reach the requested alignment.
Accessibility Considerations
Inline scroll padding can improve the visibility and predictability of horizontally or vertically scrolling content.
Keep Scroll Targets Visible
Use appropriate insets when interface elements or overlays could obscure content near the inline edges.
Maintain Keyboard Accessibility
Ensure carousel controls and other scrolling controls are keyboard accessible and have 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 Right-to-Left Layouts
Logical scroll padding automatically follows inline-start and inline-end when text direction changes.
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-inline: -20px;
}
Negative values are invalid.
Providing Too Many Values
.container {
scroll-padding-inline: 10px 20px 30px;
}
The shorthand accepts only one or two values.
Confusing Inline-Start With Left
Inline-start is the left edge in left-to-right horizontal writing, but it can be the right, top, or bottom edge in other writing modes.
Confusing Scroll Padding With Layout Padding
scroll-padding-inline affects scroll alignment, while padding-inline adds normal layout spacing.
Applying Scroll Padding to a Target
Apply scroll-padding-inline to the scroll container. Use scroll-margin-inline on individual targets.
Expecting Automatic Scroll Snapping
The property does not enable scroll snapping by itself.
Ignoring Declaration Order
A later scroll-padding-inline shorthand can override earlier inline-start or inline-end longhand declarations.
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
The browser may not achieve the requested alignment when the container cannot scroll far enough.
Important Considerations
Keep the following points in mind when using scroll-padding-inline:
- It defines scroll alignment insets at the logical inline-start and inline-end edges.
- It is a shorthand for
scroll-padding-inline-startandscroll-padding-inline-end. - It accepts one or two values.
- One value applies to both inline edges.
- Two values apply to inline-start and inline-end, respectively.
- The initial value of both longhands is
auto. - The property is not inherited.
- Each value can be a non-negative length, percentage, or
auto. - Negative values are invalid.
- Percentages are relative to the scrollport's inline-axis dimension.
- The physical edges depend on writing mode and text direction.
- It does not change normal layout spacing or element dimensions.
- It can influence scroll snapping and programmatic scrolling.
- It is useful for horizontal carousels and right-to-left interfaces.
- It does not create a scroll container or enable scroll snapping.
- Use
scroll-padding-blockfor logical block-axis insets. - Use
scroll-margin-inlinewhen individual targets need inline alignment offsets. - Available scroll range may limit the final alignment position.
- Test scrolling behavior across writing modes, directions, and viewport sizes.
Browser Support
The CSS scroll-padding-inline 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-inline.
When unsupported, scrolling generally remains functional, but the requested logical alignment insets may not be applied.
Specifications
The scroll-padding-inline 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.
