CSS Logical Properties: RTL Layouts Without left and right
Direction-aware layouts without left and right
You used margin-left, padding-right, border-left, then overrode everything for RTL with [dir="rtl"]. Logical properties are direction-aware so one set of rules works for both.
The old hack vs the modern fix
View demo.box {
margin-left: 1rem;
padding-right: 1rem;
border-top: 1px solid;
}
[dir="rtl"] .box {
margin-left: 0;
margin-right: 1rem;
padding-right: 0;
padding-left: 1rem;
}.box {
margin-inline-start: 1rem;
padding-inline-end: 1rem;
border-block-start: 1px solid;
}<!-- Tailwind v3.3+ logical utilities, flip with dir="rtl" --><!-- ms/me = margin-inline-start/end, ps/pe = padding-inline-start/end --><div class="ms-4 pe-4 border-t"> Works in LTR and RTL without extra rules</div>Logical properties browser support
Live demo
Why the modern way wins
One set of rules
inline-start and block-start follow writing direction. No [dir="rtl"] overrides.
Less code
Drop the RTL override block. Logical properties flip automatically when direction changes.
Future-proof
Works for vertical writing modes too. block and inline mean the same in any direction.
- Lines Saved
- 10+ → 5
- No RTL override block
- Old Approach
- left/right + RTL overrides
- Duplicate rules for [dir="rtl"]
- Modern Approach
- Logical properties
- inline/block, direction-aware
How it works
The old approach was to use physical properties like margin-left, padding-right, border-left, then add a [dir="rtl"] block that reset and flipped them. That meant maintaining two sets of values and missing one caused layout bugs in RTL.
Logical properties map to the writing mode. margin-inline-start is left in LTR and right in RTL. border-block-start is top in horizontal writing mode. Use inline for start/end (left/right in LTR) and block for block-start/block-end (top/bottom). Set dir on the document or a container and the same CSS works for both directions.