Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

rex — root element x-height unit

The rex unit expresses a length relative to the root element's font x-height rather than the current element's font.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

<number>rex

rex is a font-relative length unit. 1rex equals the value of 1ex on the root element, which is html in HTML. Write the number directly before the unit, for example 10rex.

ex refers to the relevant font's x-height; rex uses that measure on the root element. In contrast, rem uses the root element's font size. Do not assume a fixed conversion between rex, rem, and pixels.

In the example, both bars have equal widths despite different local font-size values. The earlier 100px declaration provides a fallback. Check support and behavior in the target browser.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>rex comparison</title>
<style>
  :root { font: 20px sans-serif; }
  .bar {
    width: 100px;
    width: 10rex;
    height: 12px;
    margin-bottom: 8px;
    background: teal;
  }
  .small { font-size: 10px; }
  .large { font-size: 40px; }
</style>
<div class="bar small"></div>
<div class="bar large"></div>
</html>

Result

Two teal bars of equal width. With rex support, each width equals 10 times the root element's x-height; otherwise each is 100px.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources