Logical Properties — CSS

Logical properties name sides by the writing direction, not by the left and right of the screen. inline is the direction a line of text runs, block is the…

Imagine your site gets an Arabic version, which is read from right to left. Say your paragraphs have a border and a gap on the left, where each line of text starts. In the Arabic version, that border and that gap should move to the right. If the CSS is written with left and right, you have to change it one rule at a time.

Properties like margin-left and padding-top point at physical sides: left, right, top, bottom. Logical properties point at sides by the direction of the writing: where a line starts and where it ends. On an English page, both give exactly the same result. The difference only shows when the writing direction changes, for example in that Arabic version.

The start side, not the left side

This rule gives a paragraph a border and a gap on the side where its lines start:

p {
  border-inline-start: 4px solid blue;
  padding-inline-start: 24px;
}

The result: on an English page, the paragraph has a blue border and a gap on the left. This is the same as writing border-left and padding-left.

Four keywords

Put these words together to get a property name. padding-block-start is padding at the start of the block direction, which is the top on a page with horizontal text. margin-inline-end is margin at the end of the line, which is the right in English.

Physical stays in place, logical follows the writing

There are two ways to change the writing direction:

padding-left is not affected by either change. A paragraph with padding-left: 24px on an Arabic page keeps its gap on the left, even though its readers start reading on the right. If you use padding-inline-start, the gap moves to the right automatically.

Common equivalents

Each physical property has a logical equivalent. inline-size is the size of an element along a line of text, and block-size is its size in the direction lines stack.

Physical Logical
margin-left margin-inline-start
margin-right margin-inline-end
padding-left padding-inline-start
padding-top padding-block-start
width inline-size
height block-size

There are short forms too (shorthands). margin-inline: auto sets the margin at the start and the end of the line at once (the usual way to centre a box). padding-block: 1rem sets the padding at the start and the end of the block direction at once.

⚠️ Start doesn't always mean left

TL;DR: Logical properties name sides by the writing direction, not by the left and right of the screen. inline is the direction a line of text runs, block is the direction new lines appear in, and start and end are the beginning and the end of a direction. On an English page, margin-inline-start is the same as margin-left, padding-inline-start is the same as padding-left, and inline-size is the same as width. When the writing direction changes to rtl (right to left) or vertical, logical properties move with it, while physical properties such as margin-left stay in place.

⚡ The start side, not the left side

Write:

p {
  border-inline-start: 4px solid blue;
  padding-inline-start: 24px;
}

Meaning: Logical properties name sides by the writing direction, not by left or right. inline is the direction a line of text runs, and start is the start of the line, where a sentence begins. On an English page, lines start on the left. So the result is the same as border-left and padding-left: a blue border and a 24px gap on the left of the paragraph.

⚡ Following the writing

Guess first: on a dir="rtl" page (Arabic, read from right to left), on which side is the gap from padding-left: 24px?

Still on the left, even though readers start reading on the right. The gap from padding-inline-start moves to the right automatically.

Meaning: Physical properties (the ones with left or right in the name) stay in place. Logical properties (the ones with start or end) follow the writing direction.

⚡ The equivalents

Meaning: On an English page, margin-inline-start is the same as margin-left, padding-block-start is the same as padding-top, and inline-size is the same as width. block is the direction lines stack in, from top to bottom.

What you will learn