Skip to content
FLAVIO COPES
flaviocopes.com
2026

The CSS calc() function

By Flavio Copes

Learn how the CSS calc() function performs math on values, like calc(80% - 100px), mixing percentages and lengths with the +, -, * and / operators.

~~~

The calc() function lets you perform basic math operations on values, and it’s especially useful when you need to add or subtract a length value from a percentage.

This is how it works:

div {
	max-width: calc(80% - 100px)
}

It returns a length value, so it can be used anywhere you expect a pixel value.

You can perform

One caveat: with addition and subtraction, the space around the operator is mandatory, otherwise it does not work as expected.

Examples:

div {
	max-width: calc(50% / 3)
}
div {
	max-width: calc(50% + 3px)
}

If you’re mixing units because you’re converting between px and rem, my free CSS units converter can help.

Tagged: CSS · All topics
~~~

Related posts about css: