Calc()
The CSS calc() function evaluates an arithmetic expression involving compatible CSS values and units to produce a computed value.
Math for Web Design
calc() is a CSS mathematical function that evaluates an arithmetic expression, including compatible units, to produce a computed style value.
- How it is used
- Expresses responsive layout and font-size relationships directly in CSS rather than hardcoding measurements for each screen size.
- How deep it goes
- Works through unit conversion and computed layout values, then specifies syntax, compatible types, scalar operands, and operator precedence.
- Examples
- Uses a viewport-sized dialog with breathing room, a percentage-minus-rem width, three columns with gutters, and a fluid font-size formula.
- What you can do after
- Applies it via CSS declarations to calculate responsive widths, gutters, dialog limits, and font sizes.
Tiny CSS Projects
The CSS calc() function computes a property value from arithmetic expressions involving CSS values and units.
- How it is used
- Uses arithmetic to size card containers and position overlapping images without hard-coding every resulting value.
- How deep it goes
- Explains subtraction, division, multiplication, negative results, and custom-property reuse through two worked card layouts.
- Examples
- Demonstrates card height subtraction, grid rows, image overlap, negative margins, and spacing that prevents clipping on short screens.
- What you can do after
- Apply calc() to build flexible card dimensions and image offsets that respond to available space and reusable size variables.
CSS in Depth, Second Edition
The CSS calc() function computes a value from arithmetic involving CSS values and units.
- How it is used
- Combines responsive viewport sizing with relative units and replaces magic-number dimension adjustments.
- How deep it goes
- Defines four arithmetic operators, explains whitespace requirements, and demonstrates responsive font and variable-based width calculations.
- Examples
- Uses responsive root typography and a column width reduced by its combined horizontal padding.
- What you can do after
- Apply calc() to build smoothly scaling font sizes and derive widths from variables instead of unexplained constants.
What to know first
- emThe em is a CSS relative length unit whose computed value is based on the applicable font size.
- proportionA ratio expressing a quantity relative to a whole or reference quantity, commonly represented as a fraction, decimal, or percentage.
Related concepts
- CSS box modeluses · The CSS box model describes each element as a rectangular box composed of content, padding, border, and margin areas that determine its dimensions and surrounding space.
- CSS math functionkind of · A CSS math function is a built-in CSS function that evaluates mathematical values or expressions in style declarations.
- CSS variableuses · A CSS custom property is an author-defined property, typically named with a leading double hyphen, whose value can be inherited and referenced in other declarations.
- height propertyconfigures · A height property specifies or reports an element’s vertical dimension.
- line equationimplements · A line equation is an equation linear in its variables that represents a straight line in two dimensions or a linear relationship in higher dimensions.
Questions about calc()
What is calc()?
The CSS calc() function evaluates an arithmetic expression involving compatible CSS values and units to produce a computed value.
Which Manning books explain calc()?
Math for Web Design, Tiny CSS Projects and CSS in Depth, Second Edition.
What should I know before learning calc()?
Manning books that teach calc() usually introduce em and proportion first.
What is calc() a kind of?
Calc() is a kind of CSS math function. A CSS math function is a built-in CSS function that evaluates mathematical values or expressions in style declarations.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


