π What Are inset-inline & inset-block?
inset-inline and inset-block are **logical positioning properties** in CSS. They allow you to position elements based on **writing mode** and **direction** rather than physical edges like left, right, top, or bottom.
They are logical equivalents of:
- inset-inline β left + right
- inset-block β top + bottom
Note
β Great for internationalization
β Avoid mixing with left/right/top/bottom for clarity
π¦ Syntax
Inset logical syntax
inset-inline: <start> <end>;
inset-inline-start: <length | auto>;
inset-inline-end: <length | auto>;
inset-block: <start> <end>;
inset-block-start: <length | auto>;
inset-block-end: <length | auto>;π Understanding Logical Directions
| Logical Side | LTR Equivalent | RTL Equivalent |
|---|---|---|
| inline-start | left | right |
| inline-end | right | left |
| block-start | top | top |
| block-end | bottom | bottom |
π 1. Basic Example: Position Element on Inline Axis
inset-inline example
.box {
position: absolute;
inset-inline: 20px; /* start & end */
}Equivalent to:
LTR β left: 20px; right: 20px;
RTL β right: 20px; left: 20px;
π 2. Different Start & End Inline Insets
inline start & end
.box {
position: absolute;
inset-inline: 10px 30px; /* start end */
}π 3. Block Axis Positioning (Top & Bottom)
inset-block example
.banner {
position: absolute;
inset-block: 15px; /* top & bottom */
}Equivalent to:top: 15px; bottom: 15px;
π 4. Different Block Start & End Positions
block start/end example
.banner {
inset-block: 20px 40px; /* block-start block-end */
}π 5. Combine Inline & Block Insets (Shorthand)
Full inset logical
.element {
position: absolute;
inset-inline: 20px;
inset-block: 10px;
}Equivalent to:
LTR β left/right: 20px, top/bottom: 10px
RTL β left/right flip automatically!
π 6. Vertical Writing Mode Example
Vertical layout example
.poem {
writing-mode: vertical-rl;
position: absolute;
inset-inline: 5px; /* applies to top/bottom in vertical mode */
inset-block: 10px; /* applies to left/right */
}Logical positioning adapts automatically β no manual calculation needed.
π§ͺ Real-World Use Cases
1οΈβ£ RTL-Friendly Sidebar
Sidebar
.sidebar {
position: fixed;
inset-inline-start: 0; /* left in LTR, right in RTL */
inset-block: 0;
width: 250px;
}Automatically places sidebar on the correct side depending on language.
2οΈβ£ Positioning a Notification Banner
Banner
.notification {
position: fixed;
inset-block-start: 20px;
inset-inline-end: 20px;
}Works universally across writing modes.
3οΈβ£ Centering an Element Using Logical Insets
Center element
.center-box {
position: absolute;
inset: 0; /* shorthand for inline + block */
margin: auto; /* centers the element */
width: 200px;
height: 100px;
}inset is the physical equivalent, whileinset-inline & inset-block give logical control.
β οΈ Common Mistakes
- β Mixing left/right with inset-inline β conflicts
- β Forgetting writing mode affects meaning of inline/block
- β Using inset logical properties on non-positioned elements
Note
π₯ Summary
inset-inline andinset-block provide powerful, writing-modeβaware positioning for modern CSS. They make your UI globally adaptable and replace the need for direction-specific properties like left, right, top, and bottom.
Learn more βMDN: inset-inline
MDN: inset-block π