What does calc() allow me to combine in a CSS value?
Quick answer
Use calc() for arithmetic that produces a value type accepted by the CSS property. You can add or subtract compatible types, such as a length and a percentage in a property that accepts both; a length and a time cannot be added. Put spaces on both sides of + and -, but spaces around * and / are optional. Newer typed arithmetic may vary across browsers. [S1] [S2]
The question, the details, the next step.
A practical checklist
Name the CSS property and check which value type it accepts.
Combine only compatible types; do not add a length to a time.
Use spaces on both sides of
+and-.Check that the completed expression produces a value valid for the property.
Check newer typed arithmetic against the browsers you need to support.
A few more useful answers
Can calc() add a percentage to a length?
Do multiplication and division need spaces?
Sources
References used for this guide.
- [S1] MDN: calc() CSS function reference developer.mozilla.org · Checked
- [S2] W3C CSS Values and Units Module Level 4: Mathematical Expressions w3.org · Checked
