Logical Properties¶
Physical properties use left, right, top, and bottom. Logical properties use inline and block, so they adapt when the writing direction changes.
Why use them¶
Physical:
Logical:
inline means along the text direction. For English that is horizontal. block means perpendicular to the text direction. For English that is vertical.
Mapping¶
| Physical | Logical |
|---|---|
margin-left |
margin-inline-start |
margin-right |
margin-inline-end |
padding-top |
padding-block-start |
padding-bottom |
padding-block-end |
width |
inline-size |
height |
block-size |
margin-inline: auto centres a block regardless of writing direction.
When to use logical properties¶
- Use them for spacing that should follow the text flow.
- Use them when a page may be translated or displayed in a different writing mode.
- For simple English-only pages, physical properties still work.
margin-inline: autois a good habit to start with.
Try it¶
- Take a card with
padding-left,padding-right,margin-top, andmargin-bottom. - Rewrite the properties using logical equivalents.
- Centre a container with
margin-inline: auto. - Add a thick border on the start side with
border-inline-start. - Check the page in the browser. It should look the same for English text.
If a logical property seems to do nothing, check the browser's support and whether the element has a writing mode override.
Next: Custom Properties