HTML & CSS Masterclass Tutorial

Comprehensive guide to modern HTML and CSS development.

Calc & Functions

CSS calc() and Functions

CSS has evolved beyond simple static values. You can now perform math directly in your stylesheet using the calc() function!

The calc() Function

Allows you to calculate lengths, percentages, and times. The true power of calc() is mixing different units. For example, you can tell an element to be exactly 100% of the screen width MINUS 50 pixels: width: calc(100% - 50px);

Other Useful Functions

  • min() / max(): Selects the smallest/largest value from a list of options.
  • clamp(min, preferred, max): Incredibly useful for fluid typography (text that grows/shrinks smoothly between a min and max size).

Try It Yourself

Edit the code below and click Run to see the result live.

Source Code
Result
Topics