CKTIS / CSS
rcap — root-element cap-height unit
The rcap unit expresses a length relative to the root element’s font cap height. On a descendant, unlike cap, it does not depend on that descendant’s font size. On the root itself, changing its font size can change a width expressed in rcap.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, exact-source example verification passed
Syntax
<number>rcaprcap is a relative length unit: 1rcap equals the value of 1cap on the root element, which is html in HTML. Write the number immediately before the unit, for example 2rcap.
cap uses the used cap height of an element’s first available font; rcap refers to the root element instead. By contrast, rem refers to its font size, not its cap height. When cap height cannot be determined, the specification requires using the font’s ascent metric.
Use this unit to relate spacing and dimensions to root typography. Changing the root font or its size can change the result; do not assume a fixed conversion to px. In the example, both bars should have equal widths despite their different local font-size values.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>rcap comparison</title>
<style>
:root { font: 20px sans-serif; }
.bar {
width: 1rcap;
height: 12px;
margin-bottom: 8px;
background: teal;
}
.small { font-size: 16px; }
.large { font-size: 48px; }
</style>
<div class="bar small"></div>
<div class="bar large"></div>
</html>Result
Two teal bars with equal widths and heights. Their exact width depends on the root font metrics.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.