CSS & LayoutBaseline · Widely

CSS Logical Properties

Mental Model

CSS Logical Properties replace physical top/right/bottom/left with flow-relative block-start/inline-end/block-end/inline-start. The style engine resolves them to physical sides based on dir="rtl" and writing-mode, eliminating duplicate RTL stylesheets.

Interactive Simulator

Physical left/right vs Logical inline-start/end

Compare how physical vs logical properties behave under dir="rtl".

Lines of Code
Before
5
After
5
Reflows / Browser Cost
Before
0 (requires [dir="rtl"] overrides)
After
0 (native Style mapping)
BeforePhysical Properties (Breaks RTL)
.callout {
  border-left: 4px solid #3b82f6;
  padding-left: 1rem;
  text-align: left;
}
Lines: 5Reflows: 0 (requires [dir="rtl"] overrides)Dependencies: Duplicate RTL CSS

Border and padding stay stuck on the left in Arabic/Hebrew.

After (Native)Logical Properties (Auto-Flips)
.callout {
  border-inline-start: 4px solid #3b82f6;
  padding-inline-start: 1rem;
  text-align: start;
}
Lines: 5Reflows: 0 (native Style mapping)Dependencies: 0 extra CSS

Automatically mirrors to the right when dir="rtl" is set.

Under the Hood

Physical directions assume every reader scans left-to-right from top-to-bottom; logical properties orient themselves to the text stream's inline and block axes during Render Tree & Layout.

  1. Axis Mapping: In horizontal ltr, inline-start maps to left and block-start maps to top. Flipping dir="rtl" remaps inline-start to right automatically.
  2. Shorthands: margin-inline: 1rem sets both start and end; inset: 0 sets all four top/right/bottom/left offsets at once.
  3. Radius & Overflow: border-start-start-radius and inline-size/block-size complete the model alongside Block Formatting Context layout.
CSS
.drawer {
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  inline-size: min(360px, 90vw);
  border-inline-start: 1px solid #27272a;
}

Problem Genealogy

  • 2005–2018: Internationalized apps ran PostCSS RTLCSS build plugins or maintained brittle [dir="rtl"] override sheets.
  • 2020+: CSS Logical Properties Level 1 achieved universal support, making single-bundle LTR/RTL/CJK layouts native.

Production Pitfalls

Production Pitfall
  • Mixing physical and logical: Writing margin-inline: 0 above margin-left: 1rem maps to the same underlying box-model slot, causing confusing cascade overrides.
  • Logical overflow-x gotcha: overflow-inline is newer than margin-inline; verify support before replacing overflow-x if targeting older browsers.
When Not to Use
  • When not to use logical properties: Do not use logical directions for inherently physical geometry (like a compass rose or video scrubber bar that always runs left-to-right).

Connections & Logical Next Steps

CSS & LayoutCSS Logical Properties

Mechanical Comparisons