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;
}
inlineis the direction a line of text runs. In English, that is left to right.startis the beginning of that direction, where a sentence begins. In English, that is the left.border-inline-startis a border on the side where lines start, here a blue border 4px thick.padding-inline-start: 24pxis a 24px gap on that same side, between the blue border and the text.
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
inline: the direction a line of text runs.block: the direction lines stack in, which is where a new line appears (top to bottom).start: the beginning of a direction.end: the end of a direction.
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:
- The
dir="rtl"attribute in the HTML.rtlmeans right to left, for Arabic or Hebrew. Lines now start on the right, sopadding-inline-startmoves to the right too. writing-mode: vertical-rlin the CSS (upright text, like traditional Japanese). A line of text now runs from top to bottom, so the start of the line is at the top, andpadding-inline-startmoves to the top too.
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
- Thinking
startalways means left.startfollows the writing direction. On adir="rtl"page,startis on the right. - Thinking
inline-sizeis always the width. Inwriting-mode: vertical-rlthe lines of text are upright, soinline-sizebecomes the height of the element. - Mixing physical and logical for the same side.
margin-leftandmargin-inline-startset the same side in English, but different sides in Arabic. Pick one way within a component.
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.