CSS Reference ยท Container Queries and Logical Properties
Logical properties and values
Overview of CSS logical properties: block and inline axes, start and end, how they map to physical sides, and which properties have logical forms.
CSS was originally written for horizontal, left-to-right text, so its properties talk about physical sides: top, left, width, height. That breaks down for languages written right to left (Arabic, Hebrew) or vertically (Japanese, traditional Chinese, Mongolian). Logical properties describe layout relative to the flow of text instead, so one rule works in every writing system.
The idea rests on two axes and two ends.
Axes and ends
- The inline axis is the direction text runs within a line. In English it is horizontal, left to right.
- The block axis is the direction lines stack. In English it is vertical, top to bottom.
- Start and end are the two ends of an axis. Inline-start is where a line begins (left in English, right in Arabic). Block-start is where the first line sits (top in English).
Two things decide the mapping: the writing-mode property (horizontal or vertical) and the direction property (left-to-right or right-to-left, also set by the dir attribute).
| Logical term | Horizontal, left-to-right | Horizontal, right-to-left | vertical-rl, left-to-right |
|---|---|---|---|
| inline-start | left | right | top |
| inline-end | right | left | bottom |
| block-start | top | top | right |
| block-end | bottom | bottom | left |
Try it
Naming patterns
Logical names replace physical words according to a small set of patterns:
| Physical | Logical |
|---|---|
width, height |
inline-size, block-size (also min- and max- forms) |
margin-top, margin-bottom |
margin-block-start, margin-block-end |
margin-left, margin-right |
margin-inline-start, margin-inline-end |
padding-* |
padding-block-*, padding-inline-* |
border-top, border-left ... |
border-block-start, border-inline-start ... |
top, left, bottom, right |
inset-block-start, inset-inline-start, inset-block-end, inset-inline-end |
border-top-left-radius ... |
border-start-start-radius ... |
text-align: left / right |
text-align: start / end |
float: left / right |
float: inline-start / inline-end |
Shorthands pair the two ends of one axis: margin-block, margin-inline, padding-block, padding-inline, border-block, border-inline, inset-block and inset-inline. To cover all four sides, write a block shorthand and an inline shorthand together.
What stays physical
- The shorthands
margin,padding,border-widthandborder-radiususe physical sides and corners. - Properties about the screen rather than the text, such as
background-positionor transforms, remain physical. overflow-xandoverflow-yhave logical counterparts (overflow-inline,overflow-block), but support is newer, so check a compatibility table first.
Usage notes
- Start with
inline-size. Replacewidthwithinline-sizeandmargin: 0 autowithmargin-inline: autofor the easiest wins. - Mirrored UIs for free. Gutters, icons and accent bars on the start side flip automatically in right-to-left pages.
- Mixing is allowed. Logical and physical properties set the same underlying values, so the later declaration wins at equal specificity. Pick one style per component.
- Do not overdo it. If a design is not meant to flip (a map, a fixed image), physical properties are fine.
Browser support
The core logical properties (sizes, margins, padding, borders, inset) are supported in all current browsers. Newer additions, such as logical overflow and some value keywords, vary, so check a compatibility table.
Related
margin-blockandmargin-inlinepadding-blockandpadding-inlineborder-blockandborder-inlineinline-size,block-size,max-block-sizewriting-modeanddirection- Lesson: Writing modes