CSS calc() Validator

Check any calc(), min(), max() or clamp() expression against the CSS type rules — including typed division.

Paste any calc(), min(), max() or clamp() expression. The validator parses it with the CSS type rules — including the new typed-arithmetic division — and tells you whether it is valid, what type it produces, and why it fails if it fails.

Also check your browser's parser

CSS.supports() asks this browser whether it accepts the expression for a property. Note that a parser can accept syntax whose computed type still fails elsewhere — the type check above is the stricter test.

The calc() type rules, in plain language

Every CSS value has a type: length, percentage, angle, time, frequency, or a plain unitless number. calc() refuses combinations whose result would be meaningless, and a refused calc() invalidates the whole declaration — the property silently falls back, which is why these bugs are so hard to spot without a checker.

Add and subtract only between compatible types: lengths with lengths (any length units may mix), percentages with percentages, and lengths with percentages because many properties accept either. A number cannot be added to a length, and an angle cannot meet a time. Multiply only when at least one side is a plain number. Divide by a plain number, or — with typed arithmetic in current browsers — by a value of the same type, which cancels the units into a unitless number.

The two classic traps

First, whitespace: + and - must have spaces on both sides. In calc(100%-50px) the -50px is tokenized as a signed dimension, not an operator, and the declaration dies. Second, division by zero: a literal zero divisor, or a sub-expression that computes to zero such as a viewport ratio at an exact breakpoint, invalidates the value at computed time. Guard ratios with clamp() so the divisor can never reach zero in your formulas.

What about var()?

A custom property's type is only known where the variable is defined (or registered with @property), so no static checker can fully type an expression containing var(). This validator treats var() as a wildcard that is compatible with anything, flags every place it had to assume, and reports the type as conditional. If you register your custom properties with @property and a concrete syntax, your own code gets the same guarantees this page checks for literals.

How to use this tool

  1. Paste your expression — with or without the outer calc() — or tap a preset chip to see a known good or bad case.
  2. Click Validate. Read the verdict, the result type, and the step-by-step notes showing how each operation was typed.
  3. If it fails, the message names the exact rule broken: type mismatch, missing spaces around + or -, an illegal multiplication, or a zero divisor.
  4. Use the result type to pick a property it fits — the page lists what the result can drive.
  5. Optionally cross-check with the CSS.supports() button, which asks your own browser whether it accepts the expression for a chosen property.

Frequently Asked Questions

The three usual causes are: missing spaces around + or - (calc(100%-50px) is tokenized as one signed value, not a subtraction), a type mismatch such as adding a number to a length or an angle to a time, and division by zero or by an incompatible type. A failed calc() invalidates the whole declaration silently, so the property keeps whatever value an earlier rule gave it.
Addition and subtraction require compatible types: lengths mix with lengths and with percentages, angles with angles, times with times, and numbers only with numbers. Multiplication requires one side to be a unitless number. Division takes a unitless divisor, or — with typed arithmetic in current browsers — a divisor of exactly the same type, which cancels the units into a unitless number.
Yes, in Chrome and Edge 140+, Safari 26+ and Firefox 158+. Dividing two values of the same type cancels the units: calc(100vw / 1px) returns the viewport width as a plain number. In older browsers the same declaration is invalid and dropped, so declare a fallback value first when you rely on it.
No static checker can: a custom property’s type depends on its definition or its @property registration, which this page cannot see. The validator treats var() as a wildcard, flags every assumption it made, and reports the result type as conditional. Registering your variables with @property restores static guarantees in your own tooling.
CSS.supports() tests whether the browser’s parser accepts a declaration for a property; type checking of calc() happens at computed-value time, and historically some expressions parse but still fail when used. The validator applies the specification’s type algebra directly, which is the stricter and more portable test.

Was this tool helpful?

Comments

Loading comments...

Check Out Other Popular Tools