CSS min() Function

Definition and Usage

CSS min() The function will select the smallest value from the comma-separated list of values as the attribute value.

Tip:You can set min() The function is considered to be used to set the maximum limit value of the element.

Example

Use min() Set the width of #div1 to a maximum of 300px, but if the viewport width is less than 600px, the width will be smaller (50%):

#div1 {
  background-color: yellow;
  height: 80px;
  width: min(50%, 300px);
}

Try It Yourself

CSS Syntax

min(value1, value2, ...)
Value Description
value1, value2, ... Required. A comma-separated list of values, from which the smallest value is selected.

Technical Details

Version: CSS Values and Units Module Level 4

Browser Support

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

Chrome Edge Firefox Safari Opera
79 79 75 11.1 66

Related Pages

Reference:CSS max() function

Tutorial:CSS Mathematical Functions