CSS padding-inline Property
The CSS padding-inline property is a shorthand that sets padding at the start and end of an element's logical inline axis.
Unlike physical padding properties, padding-inline follows the element's writing mode and text direction. It typically controls left and right padding in horizontal writing modes and top and bottom padding in vertical writing modes.
padding-inline Syntax
The padding-inline property accepts one or two non-negative length or percentage values, or a CSS-wide keyword.
Basic Syntax
selector {
padding-inline: 20px;
}
Both logical inline sides receive 20 pixels of padding.
One Value
.box {
padding-inline: 20px;
}
The same value applies to padding-inline-start and padding-inline-end.
Two Values
.box {
padding-inline: 10px 30px;
}
The first value sets inline-start padding. The second sets inline-end padding.
Different Units
.box {
padding-inline: 1rem;
}
.box {
padding-inline: 2em 3em;
}
.box {
padding-inline: 5% 10%;
}
.box {
padding-inline: 10px 2rem;
}
Calculated Values
.box {
padding-inline: calc(1rem + 5px);
}
.box {
padding-inline: clamp(1rem, 3vw, 2.5rem);
}
Functions such as calc() and clamp() allow flexible spacing while maintaining valid padding values.
CSS-Wide Keywords
.box {
padding-inline: initial;
}
.box {
padding-inline: inherit;
}
.box {
padding-inline: unset;
}
.box {
padding-inline: revert;
}
.box {
padding-inline: revert-layer;
}
CSS-wide keywords must be used alone. They cannot be combined with length or percentage values in the same declaration.
Property Values
| Value | Description |
|---|---|
<length> |
Sets padding using a non-negative length such as 10px, 1rem, or 2em. |
<percentage> |
Sets padding as a non-negative percentage of the containing block's logical width. |
0 |
Removes padding from both logical inline sides when used as the only value. |
initial |
Resets both logical inline padding sides to their initial value of 0. |
inherit |
Inherits the computed logical inline padding values from the parent element. |
unset |
Resets both sides to 0 because padding 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 | 0 for each logical inline side |
| Inherited | No |
| Applies to | All elements except certain internal table elements |
| Computed value | Computed length or percentage for each longhand |
| Animation type | By computed value type for each longhand |
| Percentages | Relative to the containing block's logical width |
| Negative values | Not permitted |
| Logical axis | Inline axis |
| Shorthand for | padding-inline-start and padding-inline-end |
Valid Values
.box {
padding-inline: 0;
}
.box {
padding-inline: 20px;
}
.box {
padding-inline: 1rem 2rem;
}
.box {
padding-inline: 5%;
}
.box {
padding-inline: calc(1rem + 5px);
}
Invalid Values
.box {
padding-inline: -10px;
}
.box {
padding-inline: auto;
}
.box {
padding-inline: 10px 20px 30px;
}
Negative values, auto, and more than two values are invalid.
How It Works
The padding-inline property creates internal spacing on both sides of an element's inline axis.
The inline axis is the direction in which text and inline-level content progress. Its physical orientation depends on the writing mode, while the start and end sides also depend on text direction.
Equal Inline Padding
.panel {
padding-inline: 20px;
background-color: #dbeafe;
border: 2px solid #2563eb;
}
In a horizontal writing mode, the panel receives 20 pixels of padding on the left and right sides.
Different Start and End Padding
.panel {
padding-inline: 10px 30px;
}
The inline-start side receives 10 pixels, while the inline-end side receives 30 pixels.
Removing Inline Padding
.panel {
padding-inline: 0;
}
Both logical inline sides are reset to zero without changing block-axis padding.
Combining Inline and Block Padding
.notice {
padding-inline: 20px;
padding-block: 15px;
background-color: #fef3c7;
border: 1px solid #d97706;
}
This provides spacing along both logical axes without relying on fixed physical sides.
Writing Modes and Text Direction
The physical sides represented by inline-start and inline-end depend on both writing-mode and direction.
| 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 |
Horizontal Left-to-Right
.box {
writing-mode: horizontal-tb;
direction: ltr;
padding-inline: 10px 30px;
}
The left receives 10 pixels and the right receives 30 pixels of padding.
Horizontal Right-to-Left
.box {
writing-mode: horizontal-tb;
direction: rtl;
padding-inline: 10px 30px;
}
The right receives 10 pixels and the left receives 30 pixels of padding.
Vertical Left-to-Right
.box {
writing-mode: vertical-rl;
direction: ltr;
padding-inline: 10px 30px;
}
The top receives 10 pixels and the bottom receives 30 pixels of padding.
Vertical Right-to-Left
.box {
writing-mode: vertical-rl;
direction: rtl;
padding-inline: 10px 30px;
}
The bottom receives 10 pixels and the top receives 30 pixels of padding.
Important Difference
Unlike padding-block, which follows the block axis, padding-inline can reverse its start and end sides when direction changes.
Physical vs. Logical Padding
Physical padding properties target fixed sides. Logical padding properties adapt to writing mode and direction.
| Property | Controls |
|---|---|
padding-left |
Physical left side |
padding-right |
Physical right side |
padding-top |
Physical top side |
padding-bottom |
Physical bottom side |
padding-inline-start |
Logical inline-start side |
padding-inline-end |
Logical inline-end side |
padding-inline |
Both logical inline sides |
Physical Padding
.box {
padding-left: 10px;
padding-right: 30px;
}
The physical left and right sides retain their assigned values regardless of writing direction.
Logical Padding
.box {
padding-inline: 10px 30px;
}
The physical sides receiving each value depend on the element's writing mode and direction.
Why Logical Properties Matter
Logical padding properties are useful for multilingual websites, reusable components, and layouts that support different writing directions.
Shorthand Behavior
The padding-inline shorthand sets padding-inline-start and padding-inline-end.
One Value
.box {
padding-inline: 20px;
}
This is equivalent to:
.box {
padding-inline-start: 20px;
padding-inline-end: 20px;
}
Two Values
.box {
padding-inline: 10px 30px;
}
This is equivalent to:
.box {
padding-inline-start: 10px;
padding-inline-end: 30px;
}
Overriding One Side
.box {
padding-inline: 20px;
padding-inline-end: 40px;
}
The inline-start padding remains 20 pixels, while the inline-end padding becomes 40 pixels.
Declaration Order
.box {
padding-inline-end: 40px;
padding-inline: 20px;
}
The later shorthand sets both logical inline sides to 20 pixels at equal cascade priority.
Interaction With Physical Properties
.box {
writing-mode: horizontal-tb;
direction: ltr;
padding-left: 40px;
padding-inline-start: 10px;
}
Both declarations target the left side in this writing mode and direction. At equal cascade priority, the later declaration takes effect.
Percentage Padding
Percentage values for padding-inline are calculated relative to the containing block's logical width.
Horizontal Writing Mode
.container {
width: 400px;
}
.box {
padding-inline: 5%;
}
If the containing block's logical width is 400 pixels, both inline sides receive 20 pixels of padding.
Different Percentage Values
.box {
padding-inline: 5% 10%;
}
The inline-start side receives 5% and the inline-end side receives 10% of the containing block's logical width.
Vertical Writing Mode
.container {
writing-mode: vertical-rl;
height: 300px;
}
.box {
padding-inline: 10%;
}
In a vertical writing mode, the containing block's logical width corresponds to its inline size, generally its physical height. If that size is 300 pixels, each inline side receives 30 pixels of padding.
Responsive Padding
.section {
padding-inline: clamp(1rem, 4vw, 3rem);
}
The padding adjusts with the viewport while remaining between 1rem and 3rem.
Important Consideration
Percentage padding depends on the containing block's logical width, so the resulting spacing can vary between horizontal and vertical writing modes.
padding-inline Example
The following example demonstrates how two-value padding-inline declarations adapt to left-to-right, right-to-left, and vertical writing modes.
HTML Example
<div class="inline-demo">
<div class="inline-item">
<h3>Left-to-Right</h3>
<div class="inline-box inline-ltr">
<span>Content</span>
</div>
</div>
<div class="inline-item">
<h3>Right-to-Left</h3>
<div class="inline-box inline-rtl">
<span>Content</span>
</div>
</div>
<div class="inline-item">
<h3>Vertical Writing</h3>
<div class="inline-box inline-vertical">
<span>Content</span>
</div>
</div>
</div>
CSS Example
.inline-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 20px;
padding: 20px;
background-color: #f1f5f9;
}
.inline-item h3 {
margin: 0 0 10px;
font-size: 16px;
}
.inline-box {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
min-height: 150px;
padding-inline: 10px 40px;
padding-block: 15px;
border: 2px solid #2563eb;
background-color: #bfdbfe;
}
.inline-box span {
padding: 8px;
background-color: #fff;
}
.inline-ltr {
writing-mode: horizontal-tb;
direction: ltr;
}
.inline-rtl {
writing-mode: horizontal-tb;
direction: rtl;
}
.inline-vertical {
writing-mode: vertical-rl;
direction: ltr;
}
Left-to-Right
Right-to-Left
Vertical Writing
The 10-pixel inline-start padding and 40-pixel inline-end padding move to different physical sides according to writing mode and direction.
Practical Content Card
.content-card {
padding-inline: 2rem;
padding-block: 1.5rem;
border: 1px solid #cbd5e1;
background-color: #f8fafc;
}
This creates consistent logical spacing around the content without requiring separate left, right, top, and bottom declarations.
Accessibility Considerations
Logical padding can help maintain readable spacing in interfaces that support different writing modes and text directions.
Support Multilingual Layouts
.content-panel {
padding-inline: 1.5rem;
padding-block: 1rem;
}
Logical spacing adapts when a component changes between left-to-right, right-to-left, or vertical writing.
Support Text Resizing
Relative units such as rem can help padding respond to user font-size preferences.
Avoid Content Clipping
Large padding values combined with fixed dimensions can reduce available content space. Test layouts with enlarged text, long words, and narrow viewports.
Maintain Usable Controls
Padding can contribute to the clickable area of interactive elements. Ensure controls remain large enough and accessible by keyboard.
Important Consideration
Padding supports readable layouts but does not replace semantic HTML, sufficient color contrast, or keyboard accessibility.
Common Mistakes
Assuming padding-inline Always Means Left and Right
In horizontal writing modes, it controls left and right padding. In vertical writing modes, it controls top and bottom padding.
Ignoring Text Direction
In horizontal right-to-left layouts, inline-start is on the right and inline-end is on the left.
Reversing the Two Values
.box {
padding-inline: 10px 30px;
}
The first value always sets inline-start padding. The second sets inline-end padding.
Using Three or Four Values
.box {
padding-inline: 10px 20px 30px;
}
The shorthand accepts only one or two values.
Using Negative Values
.box {
padding-inline: -10px;
}
Negative padding values are invalid.
Using auto
.box {
padding-inline: auto;
}
The auto keyword is not supported for padding.
Mixing Physical and Logical Padding
Physical and logical properties can target the same side. The CSS cascade determines which declaration takes effect.
Forgetting Box Sizing
Padding contributes to the element's dimensions. With box-sizing: content-box, it can increase the rendered size beyond a declared width or height.
Important Considerations
Keep the following points in mind when using padding-inline:
- It is a shorthand for
padding-inline-startandpadding-inline-end. - It controls padding along the logical inline axis.
- It accepts one or two values.
- One value applies to both logical inline sides.
- Two values apply to inline-start and inline-end, respectively.
- The physical sides depend on writing mode and text direction.
- In horizontal left-to-right layouts, inline-start is left and inline-end is right.
- In horizontal right-to-left layouts, inline-start is right and inline-end is left.
- In vertical writing modes, the inline axis generally runs vertically.
- The initial value is
0for each side. - Padding is not inherited.
- Negative values are invalid.
- The
autokeyword is invalid. - Percentage values use the containing block's logical width.
- The element's background normally extends through the padding area.
- Padding does not collapse like certain vertical margins.
- Padding contributes to the CSS box model.
- The
box-sizingproperty affects how padding contributes to declared dimensions. - Logical and physical padding declarations can target the same side.
- The CSS cascade determines which conflicting declaration takes effect.
- Logical padding is useful for multilingual and writing-mode-aware layouts.
- Relative units can help create responsive internal spacing.
Browser Support
The CSS padding-inline property is Widely available in modern browsers, including current versions of Chrome, Edge, Firefox, and Safari.
It is part of CSS Logical Properties and Values. Older browsers may not support logical padding shorthands, so projects requiring legacy browser support should verify compatibility.
Physical Fallback Example
.box {
padding-left: 20px;
padding-right: 20px;
padding-inline: 20px;
}
The physical declarations provide fallback spacing for horizontal writing modes when padding-inline is unsupported.
For current compatibility information, visit Can I Use? and search for padding-inline.
Specifications
The padding-inline property is defined in CSS Logical Properties and Values Module Level 1.
CSS Logical Properties and Values Module Level 1
The specification defines how logical padding properties map to physical sides according to writing mode and text direction.
For additional documentation and examples, consult MDN Web Docs.
