CSS padding-block Property
The CSS padding-block property is a shorthand that sets padding at the start and end of an element's logical block axis.
Unlike physical padding properties, padding-block follows the element's writing mode. In horizontal writing modes, it controls top and bottom padding. In vertical writing modes, it controls padding on the left and right sides.
padding-block Syntax
The padding-block property accepts one or two non-negative length or percentage values.
Basic Syntax
selector {
padding-block: 20px;
}
One Value
.box {
padding-block: 20px;
}
Both the block-start and block-end sides receive 20 pixels of padding.
Two Values
.box {
padding-block: 10px 30px;
}
The first value sets block-start padding. The second sets block-end padding.
Different Units
.box {
padding-block: 1rem;
}
.box {
padding-block: 2em 3em;
}
.box {
padding-block: 5% 10%;
}
.box {
padding-block: 10px 2rem;
}
CSS-Wide Keywords
.box {
padding-block: initial;
}
.box {
padding-block: inherit;
}
.box {
padding-block: unset;
}
.box {
padding-block: revert;
}
.box {
padding-block: 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 relative to the containing block's logical width. |
0 |
Removes padding from both logical block sides when used as the only value. |
initial |
Resets both logical block padding sides to their initial value of 0. |
inherit |
Uses the parent's computed logical block padding values. |
unset |
Resets both sides to 0 because padding is not inherited. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | 0 for each logical block 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 |
| Shorthand for | padding-block-start and padding-block-end |
Valid Values
.box {
padding-block: 0;
}
.box {
padding-block: 20px;
}
.box {
padding-block: 1rem 2rem;
}
.box {
padding-block: 5%;
}
.box {
padding-block: calc(1rem + 5px);
}
Invalid Values
.box {
padding-block: -10px;
}
.box {
padding-block: auto;
}
.box {
padding-block: 10px 20px 30px;
}
Negative values and auto are invalid. The shorthand accepts no more than two values.
How It Works
The padding-block property controls internal spacing on the two sides that mark the beginning and end of the block axis.
The block axis is the direction in which block-level content progresses. Its physical orientation depends on the element's writing mode.
Equal Block Padding
.panel {
padding-block: 20px;
background-color: #dbeafe;
border: 2px solid #2563eb;
}
In a horizontal writing mode, the panel receives 20 pixels of padding above and below its content.
Different Start and End Padding
.panel {
padding-block: 10px 30px;
}
The block-start side receives 10 pixels and the block-end side receives 30 pixels.
Removing Block Padding
.panel {
padding-block: 0;
}
Both logical block sides are reset to zero without changing inline-axis padding.
Background and Padding
.notice {
padding-block: 15px;
padding-inline: 20px;
background-color: #fef3c7;
border: 1px solid #d97706;
}
The background normally extends through the padding area, while the two logical padding shorthands control spacing along both axes.
Writing Modes and Logical Directions
Logical padding properties adapt to the element's writing mode instead of targeting fixed physical sides.
| 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
.box {
writing-mode: horizontal-tb;
padding-block: 10px 30px;
}
The top receives 10 pixels of padding and the bottom receives 30 pixels.
Vertical Right-to-Left Writing Mode
.box {
writing-mode: vertical-rl;
padding-block: 10px 30px;
}
The right side receives 10 pixels of padding and the left side receives 30 pixels.
Vertical Left-to-Right Writing Mode
.box {
writing-mode: vertical-lr;
padding-block: 10px 30px;
}
The left side receives 10 pixels of padding and the right side receives 30 pixels.
Text Direction vs. Writing Mode
The direction property affects the inline axis, but it does not reverse the block-start and block-end sides in a given writing mode.
.box {
writing-mode: horizontal-tb;
direction: rtl;
padding-block: 10px 30px;
}
The block-start side remains the top and the block-end side remains the bottom.
Physical vs. Logical Padding
Physical padding properties target fixed sides of an element. Logical padding properties target sides based on writing mode.
| Property | Controls |
|---|---|
padding-top |
Physical top side |
padding-bottom |
Physical bottom side |
padding-block-start |
Logical block-start side |
padding-block-end |
Logical block-end side |
padding-block |
Both logical block sides |
Physical Padding
.box {
padding-top: 10px;
padding-bottom: 30px;
}
The top and bottom padding remain fixed, regardless of writing mode.
Logical Padding
.box {
padding-block: 10px 30px;
}
The physical sides receiving padding depend on the element's writing mode.
Using Both Logical Axes
.card {
padding-block: 15px;
padding-inline: 25px;
}
The card receives 15 pixels of padding on both block sides and 25 pixels on both inline sides.
Why Logical Properties Matter
Logical properties are useful for multilingual websites, reusable components, and layouts that support different writing directions.
Shorthand Behavior
The padding-block shorthand sets two logical longhand properties: padding-block-start and padding-block-end.
One Value
.box {
padding-block: 20px;
}
This is equivalent to:
.box {
padding-block-start: 20px;
padding-block-end: 20px;
}
Two Values
.box {
padding-block: 10px 30px;
}
This is equivalent to:
.box {
padding-block-start: 10px;
padding-block-end: 30px;
}
Overriding One Side
.box {
padding-block: 20px;
padding-block-end: 40px;
}
The block-start side remains 20 pixels, while the block-end side becomes 40 pixels.
Declaration Order
.box {
padding-block-end: 40px;
padding-block: 20px;
}
The later shorthand resets both logical block sides to 20 pixels.
Interaction With Physical Properties
.box {
writing-mode: horizontal-tb;
padding-top: 40px;
padding-block-start: 10px;
}
Both declarations target the top side in this writing mode. Because they have equal cascade priority, the later declaration sets the top padding to 10 pixels.
When mixing physical and logical padding declarations, consider the cascade and the writing mode to avoid unexpected overrides.
Percentage Padding
Percentage values for padding-block are calculated relative to the containing block's logical width.
Basic Percentage Example
.container {
width: 400px;
}
.box {
padding-block: 5%;
}
In a horizontal writing mode, if the containing block is 400 pixels wide, both logical block sides receive 20 pixels of padding.
Different Percentage Values
.box {
padding-block: 5% 10%;
}
The block-start side receives 5% and the block-end side receives 10% of the containing block's logical width.
Responsive Padding
.section {
padding-block: clamp(1rem, 4vw, 3rem);
}
The clamp() function limits the padding between a minimum of 1rem and a maximum of 3rem, using 4 viewport-width units as the preferred value.
Important Consideration
In vertical writing modes, the containing block's logical width corresponds to its inline size, which is generally its physical height. Percentage padding does not always use the physical width of the containing block.
padding-block Example
The following example demonstrates how padding-block adapts to different writing modes.
HTML Example
<div class="block-demo">
<div class="block-item">
<h3>Horizontal Writing</h3>
<div class="block-box block-horizontal">
<span>Content</span>
</div>
</div>
<div class="block-item">
<h3>Vertical Right-to-Left</h3>
<div class="block-box block-vertical-rl">
<span>Content</span>
</div>
</div>
<div class="block-item">
<h3>Vertical Left-to-Right</h3>
<div class="block-box block-vertical-lr">
<span>Content</span>
</div>
</div>
</div>
CSS Example
.block-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 20px;
padding: 20px;
background-color: #f1f5f9;
}
.block-item h3 {
margin: 0 0 10px;
font-size: 16px;
}
.block-box {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
min-height: 150px;
padding-block: 10px 30px;
padding-inline: 15px;
border: 2px solid #2563eb;
background-color: #bfdbfe;
}
.block-box span {
padding: 8px;
background-color: #fff;
}
.block-horizontal {
writing-mode: horizontal-tb;
}
.block-vertical-rl {
writing-mode: vertical-rl;
}
.block-vertical-lr {
writing-mode: vertical-lr;
}
Horizontal Writing
Vertical Right-to-Left
Vertical Left-to-Right
The same padding-block: 10px 30px; declaration applies to different physical sides depending on the writing mode.
Practical Card Example
Logical padding can also be used in reusable components without assuming a particular writing direction.
.card {
padding-block: 1.5rem;
padding-inline: 2rem;
border: 1px solid #cbd5e1;
background-color: #f8fafc;
}
This gives the card consistent spacing along both logical axes, regardless of the writing mode used by the component.
Accessibility Considerations
Logical padding can help maintain readable and usable layouts across different writing modes and languages.
Provide Comfortable Internal Spacing
.notice {
padding-block: 1rem;
padding-inline: 1.5rem;
line-height: 1.5;
}
Spacing around text helps prevent content from touching borders and improves readability.
Support Different Writing Modes
.content-panel {
padding-block: 1.25rem;
padding-inline: 1.5rem;
}
Logical properties help preserve intended spacing when a layout changes from horizontal to vertical writing.
Support Text Resizing
Relative units such as rem can help padding respond to user font-size preferences.
Avoid Clipping
Large padding combined with fixed dimensions can reduce the available content area. Test layouts with enlarged text and narrow viewports.
Important Consideration
Padding can improve spacing and usability, but it does not replace semantic HTML, keyboard accessibility, or adequate color contrast.
Common Mistakes
Assuming padding-block Always Means Top and Bottom
In horizontal writing modes, padding-block controls top and bottom padding. In vertical writing modes, it controls left and right padding.
Confusing Block Start and Block End
.box {
padding-block: 10px 30px;
}
The first value always sets block-start padding. The second sets block-end padding.
Using Three or Four Values
.box {
padding-block: 10px 20px 30px;
}
The shorthand accepts only one or two values.
Using Negative Values
.box {
padding-block: -10px;
}
Negative padding values are invalid.
Using auto
.box {
padding-block: auto;
}
Padding does not support auto.
Mixing Physical and Logical Padding
Physical and logical declarations can affect the same side. Their interaction depends on writing mode and the CSS cascade.
Forgetting Box Sizing
Padding contributes to an element's dimensions. With content-box, padding increases the total rendered size beyond a declared width or height.
Important Considerations
Keep the following points in mind when using padding-block:
- It is a shorthand for
padding-block-startandpadding-block-end. - It controls padding along the logical block axis.
- It accepts one or two values.
- One value applies to both logical block sides.
- Two values apply to block-start and block-end, respectively.
- The physical sides depend on
writing-mode. - Changing
directionalone does not reverse the block axis. - 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 padding.
- Padding does not collapse like some vertical margins.
- Padding contributes to the CSS box model.
- The
box-sizingproperty affects how padding contributes to declared dimensions. - Logical and physical padding properties 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-block property is Widely available in modern browsers, including current versions of Chrome, Edge, Firefox, and Safari.
It is part of the CSS Logical Properties and Values specification. Older browsers may not support logical padding shorthands, so projects requiring legacy browser support should verify compatibility.
Physical Fallback Example
.box {
padding-top: 20px;
padding-bottom: 20px;
padding-block: 20px;
}
The physical declarations provide fallback spacing for horizontal writing modes in browsers that do not support padding-block.
For current compatibility information, visit Can I Use? and search for padding-block.
Specifications
The padding-block 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 maps to physical sides according to writing mode.
For additional documentation and examples, consult MDN Web Docs.
