Rethinking CSS direction with logical properties

Cross-browser support for CSS logical properties has reached a tipping point, making now a practical time to understand how they work. Logical properties and values replace physical directions like left, right, top, and bottom with flow-relative terms that adapt to the writing mode and direction of the content. That makes them essential for multilingual sites, but even for English-only projects they offer useful shorthand.

Consider a common centering pattern. The classic approach is verbose:

.thing {
  margin-left: auto;
  margin-right: auto;
}

One alternative is margin: 0 auto;, but that also applies top and bottom margins. With logical properties, you can target just the inline direction — the left and right sides in a horizontal writing mode — using margin-inline.

Thinking in inline and block terms

The margin-inline property sets both margin-left and margin-right. Its counterpart, margin-block, sets margin-top and margin-bottom. This pattern extends to padding and border as well. For instance, border-inline applies borders to both the left and right sides without touching the top or bottom:

Showing border-left and border-right with matching values combined together as border-inline as a single declaration, and another example showing padding-top and padding-bottoms et to 32 pixels combined to padding-block set to 32 pixels.
Rather than thinking in physical terms, like left and right, we can think of an “inline” direction and a “block” direction.

The inline direction maps to left and right in horizontal writing modes; the block direction maps to top and bottom. But those mappings shift when the writing mode changes — which is exactly the point.

Direction, writing mode, and why context matters

Traditional CSS properties were designed around English, which is written left-to-right and top-to-bottom. Other languages differ. Arabic reads right-to-left, which is why HTML offers the dir attribute:

<html dir="rtl">

CSS mirrors this with the direction property, though using the HTML attribute is recommended in case the CSS fails to load:

.foreign-language { direction: rtl; }
Two cards, one in english and one in arabic, Both cards have a subtitle in gray above a main heading in a larger black font. The english goes from left to right and indicates the direction with an arrow below the card. The arabic direction is reverse of the english.
Credit: Ahmad Shadeed

Chinese, Japanese, Korean, and Mongolian can be written either horizontally (left-to-right) or vertically (top-to-bottom). While the majority of websites in those languages render horizontally like English text, vertical writing is common on Japanese sites, often mixed with horizontal text.

baroku.co.jp

In vertical writing, Chinese, Japanese, and Korean start at the top-right corner, while Mongolian runs left-to-right. That variety is why CSS has the writing-mode property with three core values:

  • horizontal-tb: The default, handling left-to-right languages like English or French and right-to-left languages like Arabic. The tb stands for "top-to-bottom."
  • vertical-rl: Sets a right-to-left vertical orientation for languages like Chinese, Japanese and Korean.
  • vertical-lr: For vertical left-to-right languages like Mongolian.

With logical properties, spacing and layout are contextual: they depend on both writing-mode and direction, whether set via CSS or HTML. This makes it possible to reuse CSS across languages. Organizations like BBC News, which rebuild their site in more than a dozen languages, maintain the same visual styling across regions without duplicating rules per language.

Screenshot of the BBC website. The header is red with the BBC logo aligned to the right of the screen. The navigation is also in red and aligned to the right. There is a featured article with right-aligned text and a large image to the right of it. Below that are four more article cards in a single row, each with an image above a title and date and aligned right.
bbc.com/arabic

Physical properties cause concrete problems in this scenario. Using margin-left in English, for example, works fine. But if the same CSS is reused in a right-to-left context, the margin ends up on the wrong side — space appears where it shouldn't — while the text crowds the icon it should be separated from. Logical properties avoid this entirely:

Two buttons, both with an envelope icon and a label. The left-to-right version of the button on top shows the spacing between the icon and the label. The right-to-left version shows the spacing to the left of both the label and icon.

In a left-to-right language like English, margin-inline-start sets the left margin. In a right-to-left language such as Arabic, Urdu, or Hebrew, it sets the right margin, solving the layout problem shown above. With vertical text, the same property adds space at the top — where reading begins in any vertical language. The inline direction itself changes based on the element's writing-mode: when a vertical mode is active, inline handles top and bottom.

An example of the writing direction in Mongolian. (Credit: W3C)

A full mapping of logical properties

Dozens of CSS properties have logical equivalents. The tables below show physical properties on the left and their logical counterparts on the right, assuming a left-to-right horizontal mapping. Remember, however, that the logical versions change with context. These mappings use the ltr direction and horizontal-tb writing mode.

Sizing

In a horizontal writing mode, inline-size sets width and block-size sets height. In a vertical writing mode, those swap: inline-size controls height and block-size controls width.

Physical propertyLogical property
widthinline-size
max-widthmax-inline-size
min-widthmin-inline-size
heightblock-size
max-heightmax-block-size
min-heightmin-block-size

Logical sizing properties enjoy good cross-browser support.

Borders

Logical border properties have solid support across modern browsers.

Physical propertyLogical property
border-topborder-block-start
border-bottomborder-block-end
border-leftborder-inline-start
border-rightborder-inline-end

Logical properties also exist for border style, width, and color individually:

Physical propertyLogical property
border-top-colorborder-block-start-color
border-top-widthborder-block-start-width
border-top-styleborder-block-start-style

Shorthand logical border properties are also available:

Physical propertyLogical property
border-top and border-bottomborder-block
border-left and border-rightborder-inline

Margin

All individual logical margin properties are:

Physical propertyLogical property
margin-topmargin-block-start
margin-bottommargin-block-end
margin-leftmargin-inline-start
margin-rightmargin-inline-end

These have comprehensive modern support, including Samsung Internet, with Safari coverage since 12.2. Shorthands exist too:

Physical propertyLogical property
margin-top and margin-bottommargin-block
margin-left and margin-rightmargin-inline

Padding

Padding follows the same structure: replace margin with padding for the full set of properties.

Physical propertyLogical property
padding-toppadding-block-start
padding-bottompadding-block-end
padding-leftpadding-inline-start
padding-rightpadding-inline-end
padding-top and padding-bottompadding-block
padding-left and padding-rightpadding-inline

Logical padding properties have solid browser support.

Positioning

Offsets can be declared logically as well:

Physical propertyLogical property
topinset-block-start
bottominset-block-end
leftinset-inline-start
rightinset-inline-end
top and bottominset-block
left and rightinset-inline

In a horizontal writing mode, inset-block-start is equivalent to top and inset-block-end to bottom. For left-to-right direction, inset-inline-start equals left and inset-inline-end equals right. These reverse for right-to-left languages.

In a vertical writing mode with vertical-rl, inset-inline-start is equivalent to top and inset-inline-end to bottom, while inset-block-start maps to right and inset-block-end to left. With vertical-lr, the block mappings swap and inset-block-start equals left.

Logical propertyWriting modeEquivalent to:
inset-block-startHorizontal LTRtop
inset-block-startHorizontal RTLtop
inset-block-startVertical LTRleft
inset-block-startVertical RTLright

Logical positioning properties are supported in all modern browsers, though Safari support is recent only.

A newer shorthand, inset, sets all four offsets — top, right, bottom, and left — in one declaration, which is useful for full-page overlays. Despite what it might look like in DevTools, inset is a shorthand for physical values, not logical properties:

inset: 10px 20px 5px 8px; /* shorthand for physical properties not logical properties  */

Text alignment

Logical text alignment values have broad browser support. In English, text-align: start equals left and text-align: end equals right. With a rtl direction, they switch: text-align: start aligns right.

Physical valueWriting modeEquivalent to:
startLTRleft
startRTLright
endLTRright
endRTLleft

Border radius

Support for logical border-radius properties is less consistent. The spec also lacks shorthands like border-start-radius or border-end-radius, so the corner-level properties remain the main option:

Physical propertyLogical property
border-top-left-radiusborder-start-start-radius
border-top-right-radiusborder-start-end-radius
border-bottom-left-radiusborder-end-start-radius
border-bottom-right-radiusborder-end-end-radius

The corner-shape property extends border-radius by setting the type of curvature, and it also supports logical directions:

Physical valueLogical value
corner-top-left-shape: scoopcorner-start-start-shape: scoop
corner-top-right-shape: scoopcorner-start-end-shape: scoop
corner-bottom-left-shape: scoopcorner-end-start-shape: scoop
corner-bottom-right-shape: scoopcorner-end-end-shape: scoop

Corner shorthands that combine corner-shape and border-radius are likewise available:

Physical valueLogical value
corner-top: scoopcorner-block-start: scoop
corner-right: scoopcorner-inline-end: scoop
corner-bottom: scoopcorner-block-end: scoop
corner-left: scoopcorner-inline-start: scoop
corner-top-left: scoopcorner-start-start: scoop
corner-top-right: scoopcorner-start-end: scoop
corner-bottom-left: scoopcorner-end-start: scoop
corner-bottom-right: scoopcorner-end-end: scoop

Floats

Flow-relative float values lag considerably: the inline-start and inline-end values for float are currently supported only in Firefox.

Physical valueLogical value
float: leftfloat: inline-start
float: rightfloat: inline-end
clear: leftclear: inline-start
clear: rightclear: inline-end

Proposed logical properties

Logical properties for overflow and resize are proposed but currently have very poor browser support.

PhysicalLogical
resize: verticalresize: block
resize: horizontalresize: inline
overflow-yoverflow-block
overflow-xoverflow-inline

Going further

  • "RTL Styling 101", by Ahmad Shadeed, covers logical properties and layout considerations for flexbox and grid in Arabic and other right-to-left languages.
  • For vertical text, the CSS-Tricks almanac entry on text-combine-upright explains how to rotate and squeeze multiple characters into the space of one.

Examples of real-world vertical typography appear in the Web Awards for Horizontal and Vertical Writings.

Do you need to switch?

There is no urgent reason to drop physical properties from an existing codebase. But now that browser support is essentially universal, there is little reason not to adopt logical properties in new work — even if the project targets only English. They remove a category of layout bugs when content must eventually run in multiple languages or writing modes.