liveBook · Manning

Arithmetic operator

As explained in Math for Web Design

A CSS arithmetic operator is a symbol that performs addition, subtraction, multiplication, or division within a CSS mathematical expression.

CSS arithmetic operators calculate values inside CSS mathematical expressions. The four operators are addition (+), subtraction (-), multiplication (*), and division (/). CSS accepts these expressions as arguments to math functions such as calc(), rather than directly as property values. section 3.2.1

Use these rules when writing CSS arithmetic:

  • Place spaces around addition and subtraction operators; multiplication and division do not require spaces, but spacing improves readability. section 3.2.1
  • Mix only compatible units, such as lengths with lengths or angles with angles; do not combine lengths and angles. section 3.2.1
  • Keep one operand scalar for multiplication or division; division requires the scalar on the right. section 3.2.1
  • Follow parentheses, multiplication or division, then addition or subtraction; use parentheses when a different grouping is needed. section 3.2.1

Responsive width with a subtraction

A declaration such as width: 100% - 2rem; is invalid because the expression is not passed to a CSS math function. Write width: calc(100% - 2rem); instead. The browser subtracts the 2rem gutter from the available width. section 3.2.1

Table 3.1 CSS arithmetic operators

Operator

Name

Example

Result

+

Addition

16px + 24px

40px

−

Subtraction

50rem – 5rem

45rem

*

Multiplication

10em * 2

20em

/

Division

100% / 3

33.333%

Compare addition, subtraction, multiplication, and division with CSS values and their resulting values. section 3.2.1

How Math for Web Design covers it

How deep it goes
Defines four operators and explains syntax, units, scalar operands, and precedence, but defers detailed calc() treatment.
Examples
Uses width calculations, angle addition, unit validation, scalar division, and a table of operator results.
What you can do after
Apply it via calc() to construct valid CSS values with compatible units and predictable precedence.
How it connects
Connects arithmetic operators to calc(), CSS math functions, CSS units, and CSS property values.

Also explained in

Compare how 2 books explain arithmetic operator →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math for Web Design. The section links point to the parts of the book it draws on.