This note has an interactive demo. Try it in the original

calc(100cqw / 1px) used to be an invalid declaration. Now it's a number: if the container is 521 pixels wide, you get 521, with no unit attached. With Firefox 158 joining Chrome and Safari, this is called CSS typed arithmetic, and it became Baseline newly available in October 2026.

That sounds like a footnote in the calc() spec. In practice it's the bridge CSS was missing between types. A length can now become a number, and a number can become an angle, a colour hue, a column count or a counter that CSS prints on screen. Everything in the demo above is computed this way: the big pixel readout, the value in rem, how many 92px columns fit, the needle angle and the colours. The only JavaScript changes the width of the box, like resizing a window would.

What changed in calc()

The rules for calc() used to be strict. You could multiply a length by a number (200px * 4) or divide it by a number (1000px / 2), but the right-hand side of a division had to be unitless. So there was no way to ask "how many times does 1px fit into this width?".

The current CSS Values and Units Level 4 spec relaxes that. Division and multiplication can take typed values on both sides, units of the same type cancel out, and what matters is the type the whole expression resolves to. As MDN puts it, you can divide a value with one unit by a value with a different unit of the same data type, and the result is a unitless <number>. Chrome's release note for version 140 gives two examples: calc(10em / 1px) and calc(20% / 0.5em * 1px).

Once you have a number, you can:

  • use it directly in properties that take numbers (opacity, line-height, scale), or
  • multiply it by a unit to land in a different type: * 1deg gives an angle, * 1ms a time, * 1rem a length again.

This last step is the new part: a measured length can turn into an angle or a time, which is exactly the use Chrome's note highlights.

The pattern from the demo

Here's the core of the demo's CSS, trimmed:

@property --px { syntax: "<number>"; inherits: true; initial-value: 0; } @property --pxi { syntax: "<integer>"; inherits: true; initial-value: 0; } @property --cols { syntax: "<integer>"; inherits: true; initial-value: 1; } .stage { container-type: inline-size; } .scene { --px: calc(100cqw / 1px); /* length -> number */ --pxi: calc(100cqw / 1px); /* same, rounded to an integer */ --cols: max(1, round(down, 100cqw / 92px)); /* how many 92px columns fit */ } .grid { grid-template-columns: repeat(var(--cols), 1fr); } .needle { rotate: calc(180deg + var(--px) * 0.5deg); } /* number -> angle */ .tile { background: oklch(0.72 0.17 calc(var(--px) * 0.4deg)); } /* CSS prints the width by itself */ .readout { counter-reset: px var(--pxi); } .big::before { content: counter(px); } 

A few details make this work.

Registering the properties with @property. An unregistered custom property is just a token list: var(--px) pastes the text calc(100cqw / 1px) wherever it's used, and 100cqw is then resolved there. Registering --px as a <number> makes the browser compute it once on .scene and pass the resulting number down to the children.

The <integer> version rounds for you. The spec says that when a math function resolving to a <number> is used where only an <integer> is accepted, the value is rounded to the nearest integer. That's why --pxi holds 521 when the container is 520.875px wide, and why it can feed counter-reset, which only takes integers. counter() then prints it as text. In the demo, the rem readout uses the same trick: round(down, 100cqw / 1rem * 10) gives tenths, and mod() splits them into the whole and decimal parts.

round(down, 100cqw / 92px) is a column count. repeat() needs an integer, and now you can derive one from the space available: with 521px you get 5 columns, with 259px you get 2. auto-fill can lay out a similar grid, but it doesn't hand you the number, and here every other property can read --cols too.

If you read my note on progress(), this will feel familiar. progress() gives you a 0-to-1 ratio between two values; typed arithmetic is the general tool underneath, and it doesn't clamp or force a range on you.

Browser support and gotchas

According to MDN's compatibility data, dividing typed values to get a unitless number works in Chrome 140, Safari 26 and Firefox 158. web.dev's October 2026 roundup lists it as Baseline newly available with that Firefox release.

Things worth knowing before you use it:

  • Unitless divided by a unit is still invalid. calc(1000 / 2px) doesn't parse. The unit has to be on top, or on both sides.
  • The final type has to be something a property accepts. width: calc(200px * 4px) is invalid, because a squared length is meaningless. Intermediate steps can be squared, though: in my tests, Chromium 151 and WebKit 26.5 accept width: calc(10px * 10px / 1px).
  • The divisor's unit sets the scale. 100vw / 1px and 100vw / 1em are both valid but give very different numbers, and em depends on the font size where it's resolved.
  • Feature detection is one line. CSS.supports('opacity', 'calc(1px / 1px)') returns true only where the division gives a number. In CSS, wrap the typed rules in @supports (opacity: calc(1px / 1px)). Don't rely on the cascade to fall back: once a value goes through var(), an unsupported expression doesn't drop the declaration at parse time, it becomes invalid later and you end up with the initial or inherited value. The demo uses the JavaScript check and, without support, writes the same numbers into the custom properties itself. I tested that fallback in Firefox 153, which doesn't have the feature.

What to keep an eye on

  • Older browsers still in use. Baseline newly available means the latest versions of the major browsers; Firefox only got there in October 2026. Keep an @supports fallback for now.
  • Patterns built on top. Combined with sibling-index(), container units and round(), this makes CSS a small calculator for layouts. I expect more fluid-typography and "fit as many as you can" recipes that used to need a ResizeObserver.
  • Readability. A chain of calc(), round() and mod() gets cryptic fast. Naming each step with a registered custom property, as the demo does, keeps it maintainable.

Sources

Originally published at richi.codes.