function

calc() — CSS reference

Evaluate a numeric expression using ordinary operator precedence: multiplication and division before addition and subtraction. Parentheses change the grouping. Put whitespace around binary + and -. The result must fit the destination property; a length plus a time is invalid even when a term is zero. Percentages resolve in their property context.

Formal Syntax & Structure

css syntaxcss
calc(<calc-sum>)

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSS math lab</title><style>body {margin:0} .sample {height:12px;background:#006050}.parent {width:300px} .sample {width:40px;margin-bottom:4px} #a {width: calc(50% - 20px)} #b {width: calc((20px + 10px) * 2)}</style><body><div class="parent"><div id="a" class="sample"></div><div id="b" class="sample"></div></div></body></html>
CSS Reference