Logical Properties: Writing CSS That Works in RTL and Vertical Writing Modes

CSS logical properties for RTL and vertical writing: inline and block axes, logical margin, padding, inset and sizing, :dir(), and a migration checklist.

Executive Summary: Physical properties such as margin-left and width describe the screen. Logical properties such as margin-inline-start and inline-size describe the text flow, so the same stylesheet lays out correctly in English, Arabic, Hebrew and vertical Japanese. Flexbox and Grid already work this way. Converting the rest of your CSS is mostly a mechanical find-and-replace, plus a short list of things that stay physical on purpose.
Two panels showing left-to-right and right-to-left layout flow with direction arrows

The product launches in Saudi Arabia and Israel. The team adds dir="rtl" to the html element and most of the page flips correctly, because Flexbox rows reverse on their own. Then the bug reports arrive: the search icon overlaps the text because its padding is on the wrong side, the dropdown opens off the edge of the screen, the card badge sits in the wrong corner, and the breadcrumb chevrons point backward. Someone proposes a second stylesheet generated by a build tool that swaps every left and right. Now every CSS change ships twice.

CSS logical properties are flow-relative versions of the physical box properties. Instead of top, right, bottom and left, they use block-start, inline-end, block-end and inline-start, whose physical meaning depends on the element’s writing-mode and direction. They are defined in the CSS Logical Properties and Values specification, and the core set has worked in every major browser for years.

My position: write logical properties by default in every new stylesheet, even if you only ship English today. It costs nothing, reads just as clearly once you are used to it, and turns a future localization project from a rewrite into a config change.

Inline and block: the two axes

Every element has two flow-relative axes.

  • The inline axis is the direction text runs within a line. In English it runs left to right. In Arabic and Hebrew it runs right to left. In vertical Japanese it runs top to bottom.
  • The block axis is the direction lines and paragraphs stack. In English, Arabic and Hebrew that is top to bottom. In vertical Japanese the columns stack right to left, and in vertical Mongolian left to right.

“Start” and “end” follow those axes. inline-start is the left edge in English and the right edge in Arabic. block-start is the top in both, but the right edge in vertical Japanese. Two properties control the axes: direction (ltr or rtl) sets the inline direction, and writing-mode (horizontal-tb, vertical-rl, vertical-lr) decides whether lines are horizontal or vertical.

If you read the Flexbox guide, this is familiar: Flexbox’s main axis in a row is the inline axis, which is exactly why Flexbox already works in RTL.

The mapping table

This is the reference you will come back to. The “English” column shows the physical result in a left-to-right, horizontal writing mode.

Physical Logical In English In Arabic
margin-left margin-inline-start left right
margin-right margin-inline-end right left
margin-top margin-block-start top top
margin-bottom margin-block-end bottom bottom
padding-left / -right padding-inline-start / -end left / right right / left
border-left border-inline-start left right
width inline-size width width
height block-size height height
max-width max-inline-size max width max width
top inset-block-start top top
left inset-inline-start left right
border-top-left-radius border-start-start-radius top left top right
text-align: left text-align: start left right
float: left float: inline-start left right

The radius names read as border-{block}-{inline}-radius, so border-start-end-radius is the block-start, inline-end corner: top right in English, top left in Arabic.

The logical shorthands

The two-value logical shorthands are where logical CSS becomes shorter than physical CSS:

.card {
  padding-block: 1rem;          /* top and bottom */
  padding-inline: 1.5rem;       /* start and end */
  margin-inline: auto;          /* center a block horizontally */
  border-block-end: 1px solid var(--color-border);
}

.overlay {
  position: absolute;
  inset: 0;                     /* all four sides, direction-agnostic */
}

.drawer {
  position: fixed;
  inset-block: 0;               /* top and bottom */
  inset-inline-end: 0;          /* the trailing edge: right in English, left in Arabic */
  inline-size: min(24rem, 100%);
}

One caveat: the four-value shorthands such as margin: 1px 2px 3px 4px are still physical, mapping to top, right, bottom and left. A logical keyword for them has been discussed in the CSS Working Group but has not shipped. Use the -block and -inline pairs instead whenever left and right differ.

Set direction in HTML, not CSS

Put dir="rtl" and the correct lang on the html element, or on any element whose content runs in a different direction. Do not set direction: rtl in CSS for content. Direction is part of the meaning of the text, and the HTML attribute is what screen readers, search engines, browser translation and text selection use. A pure CSS direction leaves all of them believing the text is left to right.

For user-generated content where you do not know the direction, dir="auto" lets the browser detect it from the first strong character. It is the right default for comment fields, chat messages and usernames.

The things that must flip, and the things that must not

Logical properties handle boxes. Some visual details are not box properties and need a deliberate decision. The :dir() pseudo-class, supported in every major browser since late 2023, matches an element’s resolved direction, including direction inherited from an ancestor’s dir attribute.

Directional icons

Icons that mean “forward” or “back”, such as arrows, chevrons in breadcrumbs, “next” buttons and reply arrows, must mirror in RTL. Icons that depict physical objects or universal symbols must not: a checkmark, a clock, a play button for media, a logo, a phone.

.icon--directional:dir(rtl) {
  transform: scaleX(-1);
}

Mark only the icons that carry direction. Mirroring everything is as wrong as mirroring nothing; a mirrored clock is confusing, and a mirrored brand logo is a trademark problem.

Shadows, gradients and transforms

box-shadow offsets, translateX(), gradient angles and background-position keywords are physical. If a shadow should fall toward the trailing edge, or a slide-in animation should come from the inline-start side, encode the direction in a custom property:

:root { --dir: 1; }
:root:dir(rtl) { --dir: -1; }

.toast {
  box-shadow: calc(4px * var(--dir)) 4px 12px rgb(0 0 0 / 0.15);
  animation: slide-in 200ms ease-out;
}

@keyframes slide-in {
  from { translate: calc(100% * var(--dir)) 0; }
}

For gradients, the to inline-end direction keyword does not exist, but you can flip with the same --dir trick or define a separate gradient under :dir(rtl). These are exactly the details the token approach from the custom properties guide was built for.

Things that are already logical

  • Flexbox row direction and flex-start / flex-end.
  • Grid column order, start and end alignment, and line numbering.
  • text-align: start and end.
  • Container query units cqi and cqb, and viewport units vi and vb.

Watch for the physical exceptions in these systems: justify-content: left and right are physical keywords, and so are text-align: left and right. Use start and end.

Vertical writing modes in practice

Vertical text is common in Japanese, Chinese and Korean editorial design, and in Mongolian it is the norm. Even in English sites, vertical writing modes are useful for rotated table headers and sideways labels on charts, and they are much better than transform: rotate() because the element’s layout size actually changes with it.

.vertical-article {
  writing-mode: vertical-rl;      /* columns run top to bottom, stack right to left */
  block-size: 80vh;               /* the "height" of a vertical line is now its inline size */
  inline-size: auto;
}

th.rotated {
  writing-mode: vertical-rl;
  rotate: 180deg;                 /* read bottom to top, common for chart labels */
  white-space: nowrap;
}

In a vertical writing mode, every logical property you used keeps its meaning. padding-inline now pads the top and bottom of the column, margin-block-start is on the right side, and inline-size is the column’s height. A component built only with logical properties works in vertical text with no changes. A component built with physical properties needs a rewrite.

Migrating an existing codebase

  1. Add dir and lang to your test pages. Run the site with dir="rtl" before translating anything. Broken layouts show immediately.
  2. Replace mechanical pairs first. margin-left, padding-right, left:, right:, text-align: left and border-left have one-to-one replacements. Most of a migration is this step.
  3. Convert sizes where it helps. width to inline-size only matters for vertical modes. Do it in components that might render vertically; leave it elsewhere if your team prefers.
  4. Audit icons. Mark directional icons and leave the rest alone.
  5. Handle the physical leftovers. Shadows, transforms, gradients and background positions get the --dir treatment.
  6. Lint it. A Stylelint plugin such as stylelint-use-logical flags new physical properties in code review, so the migration does not regress.

If you use Tailwind, its ms-*, me-*, ps-*, pe-*, start-* and end-* utilities map to logical properties, and recent v4 releases expanded the logical set. The same migration applies to class names.

Frequently Asked Questions

What are CSS logical properties?

Logical properties are flow-relative versions of physical CSS properties. Instead of left, right, top and bottom, they use inline-start, inline-end, block-start and block-end, which map to physical sides based on the text direction and writing mode. margin-inline-start is the left margin in English and the right margin in Arabic.

Are CSS logical properties supported in all browsers?

Yes. The core logical properties for margin, padding, border, inset, sizing and text alignment have been supported in all major browsers for several years, and logical float values and the :dir() pseudo-class have been cross-browser since 2023.

Should I use direction: rtl in CSS?

Not for content. Set the dir attribute in HTML instead, because direction is part of the text’s meaning and the attribute is what screen readers, translation tools and search engines read. CSS direction only changes the visual result.

Which icons should be mirrored in right-to-left layouts?

Mirror icons that express direction or progress, such as back and forward arrows, breadcrumb chevrons and next buttons. Do not mirror icons that depict objects or universal symbols, such as checkmarks, clocks, media play buttons, phones and logos.

Describe the flow, not the screen

Physical CSS assumes one language and one orientation. Logical CSS describes how content flows and lets the browser map that to the screen for every language. Adopt it for new code now, lint for it, and your next market launch becomes a translation task instead of a CSS rewrite. CSS can now handle a surprising amount of interactive styling without JavaScript, and the :has() parent selector is the best example.

Rule of thumb: if you typed left or right, ask whether you meant start or end.

Originally posted on 7 August 2025 and post last modified on 7 August 2025

CSS Front-End Development Internationalization Logical Properties

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *