Sub topic 1
Why Physical Properties Break Across Languages
Prerequisites
This chapter assumes you know basic CSS syntax and the box model (content, padding, border, margin). You should be comfortable with width, height, margin, padding and position. You should also know what the HTML lang and dir attributes do, and that some languages are written right to left or top to bottom.
The hidden assumption in margin-left
Properties such as margin-left, padding-right and width name a side of the screen. They assume text starts at the left and runs to the right, and that lines stack from top to bottom. That is true for English. It is not true for Arabic, Hebrew, Japanese or Mongolian.
Consider a note with a colored bar and some space before its text:
<p dir="rtl" lang="ar" class="note">...</p>
<p dir="ltr" lang="en" class="note">...</p>
<style>
.note {
padding-left: 2rem;
border-left: 3px solid tomato;
}
</style>In the English paragraph, the bar and padding sit before the text, as intended. In the Arabic paragraph, the text starts at the right edge. The bar is now on the wrong side, at the end of the line, and the padding pushes the text away from nothing in particular.
What goes wrong
Physical properties fail in three common ways.
- Wrong side in right-to-left text. Spacing, borders and icons meant for the start of a line land at the end.
- Wrong meaning in vertical text. In a vertical writing mode, lines run top to bottom, so
widthandheightno longer match "along the line" and "across the lines". - Duplicate rules. The usual fix is a second set of rules, such as
[dir="rtl"] .note { padding-left: 0; padding-right: 2rem; }. These overrides grow with every component and are easy to forget.
The logical approach
Logical properties describe layout relative to the text flow instead of the screen. Rather than "left", you say "the start of the line". The browser then maps that to a physical side using the element's writing mode and direction.
.note {
padding-inline-start: 2rem;
border-inline-start: 3px solid tomato;
}The same rule now works for both paragraphs. The padding and border sit on the right of the right-to-left paragraph and on the left of the left-to-right one. No override is needed.
Physical and logical side by side
| Physical property | Logical equivalent |
|---|---|
| `width` | `inline-size` |
| `height` | `block-size` |
| `margin-left` | `margin-inline-start` |
| `padding-right` | `padding-inline-end` |
| `border-top` | `border-block-start` |
The mapping depends on context. In horizontal left-to-right text, inline-size equals width. In a vertical writing mode, it equals height.
The next chapters explain writing mode and direction, then the block and inline axes that these properties rely on.
Exercise
A stylesheet uses margin-right: 1rem on an icon that sits before a label. Why does this break in Hebrew, and which logical property fixes it?
Show answer
Hebrew is written right to left, so the start of the line is on the right. The icon appears at the right of the label, and margin-right puts the gap on the wrong side, between the icon and the edge instead of between the icon and the label. Using margin-inline-end: 1rem places the gap after the icon in the flow of the text in both English and Hebrew.