Sub topic 1
Why Physical CSS Properties Break Across Languages
Prerequisites
This chapter assumes basic CSS syntax, the box model, and familiarity with width, height, spacing, and positioning. You should also know that some languages read from right to left or arrange text vertically.
Why Physical Properties Break Across Languages
Physical properties name fixed screen directions:
margin-leftadds space on the screen's left.border-rightdraws a border on the screen's right.widthandheightdescribe horizontal and vertical dimensions.
These choices work for one layout direction, but they encode assumptions about how content flows. In a right-to-left interface, the main reading direction runs from right to left. In a vertical writing mode, text may flow from top to bottom. A rule such as padding-left: 1rem may then place spacing on the wrong side.
CSS logical properties describe the flow of the content instead. They adapt when the language or writing mode changes.
.card {
margin-inline: auto;
padding-inline: 1.5rem 1rem;
border-inline-start: 4px solid steelblue;
}Here, the border belongs at the beginning of the inline direction. It is not permanently tied to the screen's left or right edge.
> callout note > Prefer logical properties for component layout. They make the component reusable across languages and writing modes without direction-specific overrides. > ```
Writing Mode and Direction
direction describes whether inline content progresses left to right or right to left. Common values are ltr and rtl.
writing-mode describes the orientation of the writing flow. The default is horizontal-tb, meaning horizontal lines progress from top to bottom. Other modes can make lines vertical, such as vertical-rl.
Direction affects which end is the beginning of a line. Writing mode affects the orientation of the axes.
The Block and Inline Axes
The inline axis follows the direction in which text runs within a line. The block axis moves to the next line or block.
In normal English text, the inline axis is horizontal and the block axis is vertical. In a vertical writing mode, those orientations change. Logical properties follow these axes rather than the screen.
Start and End Instead of Left and Right
Use inline-start and inline-end for the beginning and end of a line. Use block-start and block-end for the beginning and end of stacked content.
For example, padding-inline-start replaces a direction-dependent left or right padding rule. border-block-end places a border after the block flow.
Exercise
Which property places a border at the beginning of the text line in both left-to-right and right-to-left layouts?
Show answer
Use border-inline-start.