Skip to content

Adding new relative units RCH and REX #6034

@chrislachance

Description

@chrislachance

Background

Currently today, there is support for relative root level 'em' width, aka. 'rem' (https://www.w3.org/TR/css3-values/#rem), but not root 'ch' nor root 'ex' (https://www.w3.org/TR/css3-values/#font-relative-lengths). I'd like to see that change.

Proposal

When considering WCAG 2.1 1.4.8 (https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-visual-presentation.html), its pretty clear that a value like 80rem won't guarantee a layout will meet this requirement. I believe that something like 80rch would be far more effective (or at least a lot closer to achieving this without JS).

As for 'rex' (which honestly would be really fun to use), some typography and visual designers suggest that vertical rhythm in a design should be driven by x-height (or 'ex'). (#22 - https://uxdesign.cc/the-ui-ux-tips-collection-volume-one-f69f0969ed17#ebf5). Using the baseline font (user preference or design choice), the design should vertically scale accordingly.

Using 'rem' / 'rch' for horizontal spacing & 'rex' for vertical seems to be more inline with the intent of spacing metrics, that are fluid based on the user's preference or style-set font family.

Advantages and Drawbacks

  • Advantage: Would round out the existing REM value for relative values
  • Advantage: UI is more flexible and consistent to user preference (if fonts aren't overwritten by a fixed style)
  • Advantage: RCH allows us to set a universally readable width at the root level, like some use REM for
  • Disadvantage: Cost of implementation for a potentially un-used unit
  • Disadvantage: Mixed support across various browsers for a bit

Current Workarounds

  • JS and CSS variables (custom properties) could do this today (https://codepen.io/chrislachance/pen/zYoJPvP?editors=1100). Does create layout instability if not properly dealt with.
  • Some fonts render 1ch or 1ex as .5em. This may work, but it would be sporadic, and miss the intent.
  • Could be faked by using .5rem, but still misses intent.
  • And for 'rch', JS could read & parse each line and see which characters overflow and adjust width dynamically.

P.S. This is my first time proposing. Thanks to Adam Argyle for pointing me in the right direction (especially to proposal with a nice template to follow!)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions