liveBook · Manning

Logical property

As explained in CSS in Depth, Second Edition

A CSS logical property expresses a dimension or position relative to writing direction rather than a fixed physical side or axis.

A logical property describes an element through its inline and block directions instead of fixed top, right, bottom, left, width, or height values. This lets the same layout adapt to right-to-left and vertical writing modes. section 3.1.2

The browser interprets inline direction as the text flow and block direction as the direction in which boxes stack. Thus, inline-size behaves like width in horizontal writing and like height in vertical writing. section 3.1.2

Common physical properties map to writing-mode-aware alternatives:

  • width becomes inline-size, and height becomes block-size. section 3.1.2
  • padding-left and padding-right become padding-inline-start and padding-inline-end. section 3.1.2
  • border-top and border-bottom become border-block-start and border-block-end. section 3.1.2
  • margin-inline, margin-block, padding-inline, padding-block, border-inline, and border-block provide useful paired-value shorthands. section 3.1.3

A direction-aware container

.container { max-inline-size: var(--column-width); margin-inline: auto; } This preserves the centered double-container pattern while expressing its maximum measure and side margins logically. In a horizontal writing mode it looks unchanged; other writing modes can reinterpret the dimensions and sides. section 3.1.3

Figure 3.5 Inline and block directions in various writing modes
figure

Compare inline and block directions across horizontal, right-to-left, and vertical writing modes. section 3.1.2

How CSS in Depth, Second Edition covers it

How deep it goes
Defines directional dimensions, sides, and shorthands, then applies them to a centered container; it stops short of detailed browser internals.
Examples
Uses inline-size, block-size, logical padding and borders, plus a max-inline-size and margin-inline container pattern.
What it assumes
Assumes familiarity with normal document flow and physical CSS dimensions while teaching inline, block, start, and end terminology.
What you can do after
Apply CSS logical properties to express layout dimensions and spacing in terms of document flow.
How it connects
Links writing modes, document flow, the box model, viewport units, and responsive layout dimensions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of CSS in Depth, Second Edition. The section links point to the parts of the book it draws on.