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.

Old way 10+ lines
.box   {  margin-left: 1rem;  padding-right: 1rem;}[dir="rtl"] .box   {  margin-left: 0;  margin-right: 1rem;}
5 lines
.box   {  margin-inline-start: 1rem;  padding-inline-end: 1rem;  border-block-start: 1px solid;}
Widely available Since 2021 96% global usage

This feature is well established and works across many devices and browser versions. It has been available across browsers since 2021.

Safe to use without fallbacks.

87+
66+
14.1+
87+
click to switch between LTR and RTL
A
Logical properties
margin-inline-start, padding-inline-end

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.

ESC