Skip to main content
CodeRocket
CSSmediumlayout

Use CSS logical properties for i18n and RTL support

rule · logical-properties

Logical properties map layout directions to the document's writing mode rather than physical screen directions, making styles work correctly in any language.

Code Examples

CSS
/* ❌ Physical — breaks in RTL */
.nav-item + .nav-item {
  margin-left: 1rem;
}
 
/* ✅ Logical — works in both LTR and RTL */
.nav-item + .nav-item {
  margin-inline-start: 1rem;
}
CSS
/* ❌ Physical icon spacing */
.button__icon {
  margin-right: 0.5rem;
}
 
/* ✅ Logical */
.button__icon {
  margin-inline-end: 0.5rem;
}

Why It Matters

Physical CSS properties (margin-left, padding-right) are hardcoded to screen directions. In right-to-left languages (Arabic, Hebrew, Persian), what should be margin-left becomes margin-right. Without logical properties, supporting RTL requires maintaining duplicate stylesheets or complex overrides with [dir=rtl] selectors. Logical properties handle this automatically.

Physical vs Logical Reference

PhysicalLogicalMeaning
margin-leftmargin-inline-startBefore text in reading direction
margin-rightmargin-inline-endAfter text in reading direction
margin-topmargin-block-startBefore block in flow direction
margin-bottommargin-block-endAfter block in flow direction
padding-leftpadding-inline-start
padding-rightpadding-inline-end
border-leftborder-inline-start
border-rightborder-inline-end
left (position)inset-inline-start
right (position)inset-inline-end
widthinline-sizeSize in writing direction
heightblock-sizeSize perpendicular to writing direction
min-widthmin-inline-size
text-align: lefttext-align: start

Shorthands

CSS
/* Inline shorthand: start | end */
margin-inline: 1rem 2rem;  /* start end */
margin-inline: auto;       /* both auto — centering */
padding-inline: 1.5rem;    /* both same */
 
/* Block shorthand */
margin-block: 1rem 2rem;   /* top | bottom */
padding-block: 2rem;       /* both same */
 
/* All sides */
margin: 1rem;     /* physical shorthand (still works) */
padding-block: 1rem;    /* top/bottom */
padding-inline: 1.5rem; /* left/right */

Positioning

CSS
/* ❌ Physical absolute positioning */
.tooltip {
  position: absolute;
  left: 0;
  top: 100%;
}
 
/* ✅ Logical */
.tooltip {
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: 100%;
}
 
/* Shorthand: inset = top right bottom left */
.overlay {
  position: absolute;
  inset: 0; /* Covers all four sides */
}

Borders

CSS
/* Left border accent on a quote — should be reading-start in RTL */
blockquote {
  border-inline-start: 4px solid var(--color-primary);
  padding-inline-start: 1.5rem;
}

Support Notes

  • Logical properties depend on browser support and writing-mode behavior, so verify the rendered output in the supported browsers and directionality modes.
  • Document any fallback physical properties only when a required browser target lacks the logical equivalent.

Verification

  1. Inspect the rendered UI at the breakpoints and interaction states affected by the rule.
  2. Confirm the computed styles match the intended fix in DevTools.
  3. Test at least one mobile and one desktop viewport before shipping.
  4. If the rule affects motion, contrast, or layout stability, verify those user-facing outcomes directly.