Logical properties make internationalization seamless. Instead of manually flipping your entire layout for RTL languages, the browser handles direction changes automatically when you use logical properties.
Logical Properties and Writing Modes
Every CSS property you have written so far that uses a direction, top, right, bottom, left, width, or height, is a physical property. It refers to a fixed point in the viewport regardless of how text flows. That works fine for English, but when the same layout needs to work in Arabic, Hebrew, Japanese, or any other writing system, those fixed directions become a problem. Logical properties describe space relative to the flow of text instead of the physical screen, and they make internationalized layouts nearly effortless.
Writing Modes and Text Flow
Before logical properties make sense, you need a mental model of how CSS thinks about text direction. Every element has two axes: the inline axis, which runs in the direction text flows (left to right in English, right to left in Arabic), and the block axis, which runs perpendicular to it (top to bottom in most writing systems). These two axes are the foundation of every logical property.
The direction property controls whether inline content flows left to right (ltr) or right to left (rtl). The writing-mode property controls whether lines stack vertically or horizontally. For most web projects you will only deal with ltr and rtl, but the logical property system handles all combinations automatically.
In production, direction is usually set by the lang and dir attributes on the <html> element rather than directly in CSS. When a browser loads a page with <html dir="rtl" lang="ar">, the entire document flips its inline axis automatically. Logical properties respond to that flip without any additional CSS changes.
Seeing Inline and Block Directions
The diagrams below use real English and Arabic copy so you can see how the same block and inline axes behave in horizontal writing modes. Labels stay in English for readability; paragraph text follows each sample language.
English (LTR, Horizontal)
First paragraph
Second paragraph
Third paragraph
Arabic (RTL, Horizontal)
ุงูููุฑุฉ ุงูุฃููู
ุงูููุฑุฉ ุงูุซุงููุฉ
ุงูููุฑุฉ ุงูุซุงูุซุฉ
The Property Map
Every physical spacing and sizing property has a logical equivalent. The naming pattern is consistent once you learn it: physical directions (top, right, bottom, left) are replaced by axis descriptors (block-start, inline-end, block-end, inline-start), and physical dimensions (width, height) are replaced by logical ones (inline-size, block-size).
Margin, Padding, and Border
The four physical sides map directly to logical sides. In a left-to-right horizontal writing mode, the mapping is straightforward:
/* Physical โ Logical */
margin-top โ margin-block-start
margin-bottom โ margin-block-end
margin-left โ margin-inline-start
margin-right โ margin-inline-end
/* Shorthand pairs */
margin-block: 1rem 2rem; /* block-start, block-end */
margin-inline: auto; /* inline-start and inline-end both auto */
padding-block: 1rem; /* top and bottom */
padding-inline: 1.5rem; /* left and right in LTR */
border-inline-start: 3px solid var(--color-accent); /* left border in LTR */
The shorthand forms margin-block, margin-inline, padding-block, and padding-inline are the ones you will reach for most often. They replace the common pattern of setting top-and-bottom or left-and-right together, and they read more clearly than their physical counterparts.
Sizing
Width and height also have logical equivalents. This matters most when an element needs to behave differently depending on whether text flows horizontally or vertically:
width โ inline-size
height โ block-size
max-width โ max-inline-size
min-width โ min-inline-size
max-height โ max-block-size
min-height โ min-block-size
In horizontal writing modes, inline-size behaves exactly like width. The benefit only becomes visible when writing mode changes or when you want code that communicates intent: an element constrained by max-inline-size is explicitly constrained in the text flow direction, which is a more meaningful description than "maximum width."
Positioning and Inset
Positioned elements use the inset shorthand and its logical variants instead of individual top, right, bottom, and left properties:
top โ inset-block-start
bottom โ inset-block-end
left โ inset-inline-start
right โ inset-inline-end
/* Shorthand */
inset: 0; /* all four sides */
inset-block: 0; /* top and bottom */
inset-inline: 0; /* left and right in LTR */
Text Alignment
text-align: left and text-align: right also have logical equivalents:
text-align: left โ text-align: start
text-align: right โ text-align: end
Using start and end means text that is aligned to the start of the line in English will automatically align to the right edge in an RTL context, which is almost always the correct behavior.
Real Text in RTL Layouts
Logical spacing and sizing only pay off when real copy and components flip together. The article card below uses logical properties throughout. Switch among English, Arabic, and Hebrew to see the same CSS reflow without a separate stylesheet.
Before and After: Three Real Patterns
The demo below shows three common layout patterns rewritten from physical to logical properties. Use the direction toggle to switch between LTR and RTL and watch how the logical version adapts automatically while the physical version breaks.
Pattern 1: Active Nav Link with Border Accent
Pattern 2: Card Body with Asymmetric Spacing
Card content with a left indent and uniform padding.
Card content with a start indent and uniform padding.
Pattern 3: Centered Constrained Prose
This paragraph is centered using max-width with margin-left: auto and margin-right: auto, with text-align: left.
This paragraph is centered using max-inline-size with margin-inline: auto, with text-align: start.
These samples use English on purpose so you can compare physical and logical layout. Flipping dir does not make English read like Arabic or Hebrew, so punctuation may look misplaced even when the CSS is correct. For real RTL copy, use the language toggle demo above.
Vertical Writing Modes
Traditional Japanese and Chinese layouts can run vertically. The writing-mode property sets orientation; logical properties still refer to inline and block relative to that mode, not to the physical screen.
Horizontal (Default)
This is horizontal text, reading left to right, top to bottom.
writing-mode: horizontal-tb;
Vertical Right-to-Left
็ธฆๆธใใฎๆฅๆฌ่ชใใญในใใงใใๅณใใๅทฆใธใไธใใไธใธ่ชญใฟใพใใ
writing-mode: vertical-rl;
Vertical Left-to-Right
่ฟๆฏๅ็ด็ไธญๆๆๆฌใไปๅทฆๅฐๅณ๏ผไปไธๅฐไธ้ ่ฏปใ
writing-mode: vertical-lr;
A margin-inline-start always marks the start of the inline direction, whether that edge is on the left, right, top, or bottom for the current writing mode.
Using DevTools to Inspect Direction
Chrome and Edge DevTools make it easy to test logical properties without deploying RTL content. In the Elements panel, select the <html> element and double-click the dir attribute to change it from ltr to rtl. Every logical property on the page will instantly respond. This is the fastest way to verify that your layout holds together before handing it off to an internationalization team.
You can also add a temporary direction: rtl rule to :root in the Styles panel. The difference between the two approaches is that changing the HTML attribute simulates a real RTL document, while the CSS rule changes direction without affecting attributes like dir that assistive technology and bidirectional text algorithms rely on. For layout testing, either works. For accessibility auditing, use the attribute.
In the Computed tab of DevTools, logical properties show their resolved physical equivalents. If you set margin-inline-start on an RTL element, the Computed tab shows the resulting margin-right value. This is useful for debugging cases where a logical property is not producing the spacing you expected.
When to Use Logical Properties
For sites that will only ever be in one language with one writing direction, logical properties are primarily a style choice. They make code more expressive: padding-inline communicates "space on the sides of the text flow" more clearly than padding-left and padding-right separately. Many developers adopt them as a default for this reason alone.
For any site that serves RTL languages, logical properties are not optional. A layout built with physical properties in a left-to-right context will require significant rework to support Arabic or Hebrew, typically a large block of overrides wrapped in a [dir="rtl"] selector. A layout built with logical properties from the start requires no such overrides because the browser handles the flip automatically.
The practical approach is to use logical properties by default for all new CSS you write, particularly spacing, sizing, and positioning. Physical properties still have their place for things that are genuinely tied to the screen, such as a fixed element anchored to the right edge of the viewport regardless of text direction. For everything else, logical properties are the better default.
Browser support for logical properties is excellent across all modern browsers. The only meaningful caveat is that some shorthand logical properties like inset-inline arrived slightly later than the longhand forms. If you need to support older browser versions, the longhands (inset-inline-start, inset-inline-end) are safer than the shorthand.
Teaching Video Checklist
When you record your teaching video, make sure your teammates come away understanding these concepts:
- The inline and block axes and how they change between left-to-right and right-to-left writing modes
-
At least three logical property pairs mapped to their physical equivalents, such as
margin-inlinefor horizontal margin andpadding-blockfor vertical padding -
A live direction toggle showing the same layout flip between
ltrandrtlwithout rewriting physical properties -
When
inline-sizeandblock-sizereplacewidthandheight, and when physical properties are still appropriate - One section of your portfolio refactored from physical spacing to logical properties
Start by toggling dir="rtl" on a container that uses only logical properties, then repeat with physical properties so teammates can see which approach requires extra overrides.
Resources
- MDN: CSS Logical Properties and Values — Overview and property mapping tables
- MDN: writing-mode — How block and inline axes are established
- MDN: direction — Controlling inline text flow
- web.dev: Logical Properties — Practical migration guide from physical to logical CSS
- Can I Use: CSS Logical Properties — Current browser support data