CSS clamp() Function

Definition and Usage

CSS's clamp() Function used to set a value that will adjust adaptively between the minimum and maximum values based on the viewport size.

clamp() The function has three parameters: minimum value, preferred value, and maximum value. If the preferred value is within the specified range, the browser will choose the preferred value; otherwise, the browser will choose the minimum value or the maximum value.

Example

Set the minimum font size of the <h1> element to 2rem and the maximum font size to 3.5rem. At the same time, set the minimum font size of the <p> element to 1rem and the maximum font size to 2.5rem:

h1 {
  font-size: clamp(2rem, 2.5vw, 3.5rem);
}
p {
  font-size: clamp(1rem, 2.5vw, 2.5rem);
}

Try It Yourself

CSS Syntax

clamp(min, preferred, max)
Value Description
min Optional. Specify the minimum allowed value.
preferred Required. Specify the preferred value.
max Optional. Specify the maximum allowed value.

Technical Details

Version: CSS Values and Units Module Level 4

Browser Support

The numbers in the table represent the browser version that first fully supports this function.

Chrome Edge Firefox Safari Opera
79 79 75 13.1 66