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

CSS max() Function

CSS max() Function

CSS Functions CSS Functions

Example

Use the max() function to set the width of #div1 to the larger value, taking the maximum of 50% or 300px:

#div1

{

background-color:

yellow

;

height:

100

px

;

width:

max

(

50

%

,

300

px

)

;

}

Try it »


Definition and usage

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

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

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

width: max(10vw, 4em, 80px);

In the example above, the width will be at least 80px, unless the viewport is wider than 800px or an em is wider than 20px. Simply put, the minimum width is 80px. You can also think of the max() value as providing the smallest possible value for a property.

Supported version: CSS3


Browser support

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

function
max() 79.0 79.0 75.0 11.1 66.0

CSS Syntax



max(value1, value2, ...)

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

CSS Functions CSS Functions