Math Functions

calc(), min(), max(), clamp()

FunctionExampleMeaning
calc()width: calc(100% - 240px)mix units in a calculation
min()width: min(90%, 800px)the smaller value
max()padding: max(1rem, 3vw)the larger value
clamp()font-size: clamp(1rem, 2.5vw, 2rem)preferred value, kept between a min and a max

Fluid Typography

Example

The heading grows with the window but never below 20px or above 40px. Resize the code runner to see it:

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    h1 { font-family: Arial; font-size: clamp(20px, 6vw, 40px); color: #04AA6D; }
    .wrap { width: min(100%, 420px); margin-inline: auto; background: #f1f1f1; padding: 10px; font-family: Arial; }
  </style>
</head>
<body>

<h1>Fluid heading with clamp()</h1>
<div class="wrap">This box is 100% wide on small screens and at most 420px.</div>

</body>
</html>

Result