clamp()

The clamp() CSS function clamps a middle value within a range of values between a defined minimum bound and a maximum bound. The function takes three parameters: a minimum value, a preferred value, and a maximum allowed value.

Parameters

The clamp(min, val, max) function accepts three comma-separated expressions as its parameters.

min

The minimum value is the smallest (most negative) value. This is the lower bound in the range of allowed values. If the preferred value is less than this value, the minimum value will be used.

val

The preferred value is the expression whose value will be used as long as the result is between the minimum and maximum values.

max

The maximum value is the largest (most positive) expression value to which the value of the property will be assigned if the preferred value is greater than this upper bound.

Example