Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS min() Function

CSS min() Function

CSS Functions CSS Functions

Example

Use the min() function to set the width of #div1 to the smaller value, taking the minimum of 50% or 300px:

#div1

{

background-color:

yellow

;

height:

100

px

;

width:

min

(

50

%

,

300

px

)

;

}

Try it »


Definition and usage

The min() function lets you select the smallest value from a comma-separated list of expressions as the value of a property.

The min() function accepts one or more comma-separated expressions as its arguments; the value of the expression with the smallest number becomes the value of the specified property.

/* 属性: min(expression [, expression]) */

width: min(1vw, 4em, 80px);

In the example above, the width is at most 80px. If the viewport is narrower than 800px, or an em is narrower than 20px, it will be smaller. In other words, the maximum width is 80px,

Supported version: CSS3


Browser support

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

function
min() 79.0 79.0 75.0 11.1 66.0

CSS Syntax



min(value1, value2, ...)

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

CSS Functions CSS Functions