π What Are padding-inline & padding-block?
padding-inline andpadding-block are **logical padding properties** that adapt to writing mode, text direction (LTR/RTL), and vertical text flow. Instead of using physical sides like padding-left or padding-top, these properties use **logical directions**:
- π inline axis β text direction (left β right OR top β bottom)
- π block axis β line stacking direction (vertical spacing)
Note
β RTL-friendly
β Future-proof for international layouts
π¦ Syntax
Logical padding syntax
padding-inline: <start> <end>;
padding-block: <start> <end>;
padding-inline-start: <size>;
padding-inline-end: <size>;
padding-block-start: <size>;
padding-block-end: <size>;π Understanding Logical Directions
| Logical Side | Equivalent (LTR) | Equivalent (RTL) |
|---|---|---|
| inline-start | left | right |
| inline-end | right | left |
| block-start | top | top |
| block-end | bottom | bottom |
π 1. Basic Example: Padding on Inline Axis
padding-inline example
.box {
padding-inline: 20px; /* start & end */
}Equivalent to:
padding-left: 20px; padding-right: 20px; in LTR
Automatically flips in RTL.
π 2. Different Padding for Start & End
padding-inline start & end
.box {
padding-inline: 10px 30px; /* start end */
}π 3. Padding on Block Axis (Top & Bottom)
padding-block example
.container {
padding-block: 16px; /* top & bottom */
}Equivalent to:
padding-top: 16px; padding-bottom: 16px;
π 4. Different Padding for Block Start & End
padding-block example
.container {
padding-block: 8px 40px; /* block-start block-end */
}π 5. Combining Inline & Block Padding
Combined padding
.card {
padding-inline: 20px;
padding-block: 15px;
}Clean, modern spacing for components that support all writing modes.
π 6. RTL Language Support Example
RTL friendly
.content {
direction: rtl;
padding-inline: 1.5rem;
}In RTL, padding applies automatically to the right & left correctly β no separate RTL stylesheet needed!
π 7. Vertical Writing Mode Example (Japanese Layout)
Vertical writing mode
.poem {
writing-mode: vertical-rl;
padding-inline: 20px; /* now top & bottom */
padding-block: 10px; /* now left & right */
}Logical properties adapt automatically β no need to rethink spacing.
π§ͺ Real-World Use Cases
1οΈβ£ Universal Components (Cards, Buttons, etc.)
Universal component spacing
.button {
padding-inline: 1rem;
padding-block: 0.5rem;
}2οΈβ£ Navigation Menus That Support RTL
RTL navigation
.nav-item {
padding-inline: 12px;
}3οΈβ£ Responsive Article Layout
Article example
.article {
padding-block: 2rem;
padding-inline: 1rem;
}β οΈ Common Mistakes
- β Mixing physical and logical padding (causes conflicts)
- β Forgetting logical padding changes meaning when writing mode changes
- β Using inline/block padding when fixed left/right is needed for a design
Note
π₯ Summary
padding-inline andpadding-block provide modern, writing-modeβaware spacing that adapts to language direction and layout flow. They simplify UI development and make your CSS globally compatible.
Learn more βMDN: padding-inline
MDN: padding-block π