🍋
Menu
Best Practice Beginner 1 min read 255 words

CSS Logical Properties for International Layouts

Use CSS logical properties for layouts that work correctly in left-to-right, right-to-left, and vertical writing modes.

Key Takeaways

  • Logical properties replace physical properties (left/right/top/bottom) with flow-relative equivalents (inline-start/inline-end/block-start/block-end) that adapt automatically to writing direction and text orientation.
  • They're especially important in design systems and component libraries that may be used in internationalized applications.
  • ### Physical vs Logical `margin-left: 1rem` always adds space on the left side, regardless of text direction.

CSS Logical Properties

Logical properties replace physical properties (left/right/top/bottom) with flow-relative equivalents (inline-start/inline-end/block-start/block-end) that adapt automatically to writing direction and text orientation.

Physical vs Logical

margin-left: 1rem always adds space on the left side, regardless of text direction. In a right-to-left language like Arabic, this pushes content away from the reading start — the opposite of the intent. margin-inline-start: 1rem adds space at the start of the inline axis, which is left in LTR and right in RTL. The same CSS works correctly in both directions.

Property Mapping

padding-leftpadding-inline-start. margin-rightmargin-inline-end. topinset-block-start. border-bottomborder-block-end. widthinline-size. heightblock-size. text-align: lefttext-align: start.

When to Use Logical Properties

Use logical properties in all new CSS. Even if you don't currently support RTL languages, logical properties cost nothing extra and future-proof your styles. They're especially important in design systems and component libraries that may be used in internationalized applications.

Browser Support

Logical properties are supported in all modern browsers (Chrome 87+, Firefox 66+, Safari 14.1+, Edge 87+). For older browser support, use a PostCSS plugin that generates physical property fallbacks. The fallback approach is margin-left: 1rem; margin-inline-start: 1rem — browsers that understand logical properties use the latter.

Practical Adoption

Start by replacing padding and margin on components. Then update border properties and positioning. Finally, convert width/height to inline-size/block-size. Use your linter to flag physical properties in new code. For existing codebases, migrate gradually — component by component rather than a big-bang rewrite.

相关工具

相关格式

相关指南