ToolStudio.es
Free, no limits

CSS calc() generator

Build calc() expressions that mix units, check they are valid and see what they compute to.

Free with no limits: adjust the controls, see the result instantly and copy the CSS.
Settings
Examples
Expression
Context used to compute the result
Preview
Result: 920 px
CSS
width: calc(100% - 280px);

What is CSS calc() for?

calc() lets you do maths with different units in CSS: the full width minus a fixed sidebar, the viewport height minus a header, a font size that adds a rem base and a vw part. It solves layouts that would otherwise need JavaScript, but it has strict rules, and an invalid expression is silently ignored by the browser, so the declaration just does nothing.

This generator builds the expression from terms and operators. Each term is a value with a unit (px, rem, em, %, vw, vh, vmin, vmax or ch), joined with +, -, * or /. It checks the rules as you go: spaces around + and -, and a unitless number on one side of every multiplication and division. If something is wrong, it tells you what.

It also shows what the expression computes to in pixels for a context you define: the parent width (which % refers to for width, margin and padding), the viewport size, and the root and element font sizes. Choose the CSS property you are writing (width, height, margin, padding, font-size, top and others), because the meaning of % depends on it. Presets cover the classic cases: full width minus sidebar, centered column, full height minus header and fluid padding.

Seeing the computed value is the quickest way to catch mistakes, such as a % that refers to the parent height when you expected the width, or an em that is relative to a different font size than you thought. The generator runs in your browser and is free to use without limits: no sign-up and no Pro needed.

How to build a calc() expression

  1. Start from a preset or add your first term (value and unit).
  2. Add more terms with + - * or / operators.
  3. Choose the CSS property and set the context: parent width, viewport, root and element font size.
  4. Fix any rule error shown and check the computed px result.
  5. Copy the CSS declaration.

Common calc() patterns

  • Content width next to a fixed sidebar: width: calc(100% - 280px).
  • Full height below a header: height: calc(100vh - 64px).
  • A centered column with side gutters: calc(100% - 2rem).
  • Fluid padding that combines rem and vw.
  • Equal columns with gaps: calc((100% - 2 * 16px) / 3).
  • Positioning an element at the centre minus half its size.

calc() rules that trip people up

  • + and - need spaces on both sides: calc(100% - 20px) works, calc(100%-20px) is invalid.
  • * needs a unitless number on at least one side: calc(2 * 1rem) is valid, calc(2px * 1rem) is not.
  • / needs a unitless number on the right: calc(100% / 3) is valid, calc(100px / 2px) is not.
  • Dividing by zero makes the declaration invalid.
  • Nested parentheses are allowed: calc((100% - 32px) / 3).

What % means depends on the property

For width, and for margin and padding on any side, % refers to the width of the containing block. For height and top/bottom it refers to its height. For font-size it refers to the parent's font size. That is why the generator asks for the property: the same calc(50% + 1rem) gives different pixels in each case.

Frequently Asked Questions

Is the calc generator free?

Yes. The CSS generators are free to use without limits, with live preview and Copy CSS.

Why is my calc() ignored by the browser?

Usually a missing space around + or -, or a multiplication or division without a unitless number. The generator checks both rules.

Can I mix units like % and px?

Yes, that is the main purpose of calc(). The browser resolves each unit and then does the maths.

calc() or clamp()?

calc() computes one value from a formula. clamp() keeps a value between a minimum and a maximum; for fluid sizes, use the clamp generator.

Is calc() supported by browsers?

Yes, calc() is supported by all current browsers.

Related tools

Development

CSS Clamp Generator

Generate CSS clamp() values for fluid font sizes and spacing from a min and max size and viewport range. Free, no limits.

CSSclamp()Responsive
Try this tool
Development

CSS Border Radius Generator

Create CSS border-radius values visually, from simple rounded corners to organic blob shapes, and copy the shortest CSS. Free, no limits.

CSSBorder Radius
Try this tool
Development

CSS Box Shadow Generator

Create CSS box shadows with several layers, inset shadows and presets, and copy the CSS. Free, no limits.

CSSBox Shadow
Try this tool
Development

CSS Minifier

Minify CSS online with structural optimisation that merges rules and declarations. See the bytes saved, all in your browser.

CSSMinify
Try this tool