The shorthand gap in logical properties

CSS logical properties cover longhands well, but the shorthands are another matter. As Miriam Suzanne points out, logical properties let sites be optimized in advance with little effort, yet the moment you want to set several properties at once you fall back on shorthands like margin and padding, which only set physical dimensions. That leaves logical properties feeling like a second-class feature of the language.

Some ground has been gained: 2-value shorthands such as margin-block, which sets both -block-start and -block-end, are implemented and are described as useful and concise. The 4-value shorthands, however, have not kept pace. A size shorthand cannot set inline-size, and inset does not include inset-block-start.

The trade-off authors face today

The practical result is a choice between two imperfect options: use longhands to support flow-relative terms like block-start and inline-start, or keep the ergonomics of shorthands that resolve to physical terms such as top, bottom, left and right. Authors with years of CSS behind them can adapt out of muscle memory, but the decision has real consequences — especially for multi-lingual sites.

Miriam notes that the CSS Working Group has been working on this since 2017, and there is some momentum to take it up now.

A mode-switching at-rule

The 2021 proposal addresses the compatibility problem directly: shorthand properties cannot simply switch from physical to flow-relative terms without breaking things. The suggested alternative is a higher-level instruction near the top of a stylesheet — an at-rule that declares which “mode” the stylesheet is operating in.

<coordinate-mode> = [ logical | physical ] or [ relative | absolute ] or ...

@mode <coordinate-mode>; /* must come after @import and before any style rules */

@mode <coordinate-mode> { <stylesheet> }

selector {
  property: value  !<coordinate-mode>;
}

How to move it forward

  • Support Miriam’s work financially. Her CSS Working Group contributions are a labor of love that depend on sponsorships.
  • Join the discussion on her proposal, published in 2021 and open to comment.