CSS max() Function

Definition and Usage

CSS max() The function selects the largest value from the comma-separated list of values as the attribute value.

Example

Use max() Set the width of #div1 to at least 300px, but if the viewport width exceeds 600px, the width will be wider (50%):

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

Try It Yourself

CSS Syntax

max(value1, value2, ...)
Value Description
value1, value2, ... Required. A comma-separated list of values, from which the largest 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 min() function

Tutorial:CSS Mathematical Functions