The missing one-to-one property reference
CSS has no function that reads another property's value into the current declaration and keeps tracking it as that value changes. Lea Verou explained in 2021 why this general-purpose idea, though proposed many times, is not feasible to implement. The CSSWG process is not always linear, so the feature remains conceivable, but nothing in the current language does the job directly. What follows are the supported workarounds, plus one specification that points at where things may go.
Saving the value in a custom property
The reliable route is to store the value as a custom property and reference it wherever needed. This requires knowing the value up front, which limits its usefulness, but it covers a range of cases. In the example of sizing a border-radius from a button's height, the height is declared once as --button-height and reused:
button {
--button-height: 3rem;
height: var(--button-height);
border-radius: calc(var(--button-height) * 0.3);
}
Moving that custom property higher in the cascade widens its reach across containment contexts:
:root {
/* Declare here to use anywhere */
--button-height: 3rem;
header {
--header-padding: 1rem;
padding: var(--header-padding);
/* Height is unknown (but we can calculate it) */
--header-height: calc(var(--button-height) + (var(--header-padding) * 2));
/* Which means we can calculate this, too */
border-radius: calc(var(--header-height) * 0.3);
button {
/* As well as these, of course */
height: var(--button-height);
border-radius: calc(var(--button-height) * 0.3);
/* Oh, what the heck */
padding-inline: calc(var(--button-height) * 0.5);
}
}
}
inherit(): specified, not yet shipped
The inherit() CSS function, unsupported in every current browser, would return a parent's property value and let value functions such as calc() modify it — the inherit keyword generalized to any parent property. The CSS Values and Units Module Level 5 draft defines it for custom properties only, which adds nothing over the previous method, but the intent is eventual coverage of all properties. Compared with custom properties, it depends on the parent having the fixed dimension. It also would not interpolate: an auto value computing to 3rem is still inherited as auto, which may compute differently in the child's context. That is occasionally acceptable and sometimes not.
header {
height: 3rem;
button {
height: 100%;
/* Get height of parent but use it here */
border-radius: calc(inherit(height) * 0.3);
padding-inline: calc(inherit(height) * 0.5);
}
}
What works today, property by property
aspect-ratio
This property sets one dimension from the other, in either direction. The actual value is never retrieved, but a ratio needs no knowledge of the value or its unit:
div {
width: 30rem;
/* height will be half of the width */
aspect-ratio: 2 / 1;
/* Same thing */
aspect-ratio: 3 / 1.5;
/* Same thing */
aspect-ratio: 10 / 5;
/* width and height will be the same */
aspect-ratio: 1 / 1;
}
currentColor and its proposed siblings
currentColor resolves to the computed value of color and, being a <color>, is valid anywhere that data type is accepted on the same element. Set color: red directly or by inheritance and border-color: currentColor follows, updating automatically if color changes:
body {
/* We can set color here (and let it be inherited) */
color: red;
button {
/* Or set it here */
color: red;
/* And then use currentColor here */
border-color: currentColor;
border: 0.0625rem solid currentColor;
background: hsl(from currentColor h s 90);
}
}
A currentBackgroundColor / currentBackground keyword has already been proposed, which would allow borders derived from the background, for example border-color: hsl(from currentBackgroundColor h s calc(l - 30)) or border-color: color-mix(currentBackgroundColor, black, 30). The same logic invites currentWidth, currentHeight and similar keywords.
from-font
Available only on text-decoration-thickness, from-font addresses underlines that stay 1px regardless of font-size and font-weight. The value is not generated by CSS: the font maker optionally embeds it in the font file. When absent, auto applies and browsers resolve it to 1px. The fallback is acceptable for non-critical cases but unreliable. A percentage value tied to font-size — somewhere between 8% and 12% — is the dependable substitute.
Units as implicit references
vw and vh already express viewport width and height as percentages, usable alone or inside calc() in any property taking a <length>. Less familiar units follow the same pattern:
1ex: the computed x-height1cap: the computed cap height1ch: the computed width of the0glyph1lh: the computedline-height, which can determine the height of a box with a fixed line count, provided nothing trims or adds to the content box (for instancetext-boxorpadding)
Logical variants (vi, vb) and root variants (rex, rcap) work in any property that accepts a <length>.
Container query units as a stand-in for inherit()
Within container size queries, six units describe the query container:
1cqw,1cqh: 1% of the container's computed width or height1cqi,1cqb: 1% of its computed inline or block size1cqmin,1cqmax: the smaller or larger of1cqiand1cqb
These reproduce the earlier inherit() example for dimensions:
header {
height: 3rem;
container: header / size;
@container header (width) {
button {
height: 100%;
border-radius: calc(100cqh * 0.3);
padding-inline: calc(100cqh * 0.5);
}
}
}
Because the query targets a container and its direct child, a shorter form works without declaring or querying a named container — only its units are needed:
header {
height: 3rem;
container-type: size;
button {
height: 100%;
border-radius: calc(100cqh * 0.3);
padding-inline: calc(100cqh * 0.5);
}
}
Two limits apply. inherit() would cover any property; container query units cover sizes only. And they do not work with inline containers — note the horizontally stretched container in the example — so they cannot solve every problem.
Where this leaves us
A compute()-style function remains the cleanest possible answer:
button {
/* self could be the default */
border-radius: compute(height, self);
/* inherit could work like inherit() */
border-radius: compute(height, inherit);
/* Nice to have, but not as important */
border-radius: compute(height, #this);
}
If that proves impossible, more currentColor-like keywords are the next best option. Apart from the font-supplied and therefore optional from-font, keywords such as currentWidth and currentHeight would reduce the number of custom properties and make stylesheets easier to read. Until then, custom properties, aspect-ratio and the length and container units above handle many cases, and inherit() is expected eventually. Most existing options are oriented toward widths and heights, which is appropriate given that dimensions are the largest part of the problem.
Sponsor CSS-Tricks!
We've got lots of ways to help you connect with the greatest front-end community in all the land.



