A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/css/css-max-function/ below:

CSS max() Function - GeeksforGeeks

CSS max() Function

Last Updated : 15 Jul, 2025

The max() function in CSS is used to set the maximum of the numbers given. It is used to return the largest value from a set of comma-separated values. It can accept length, frequency, integer, angle, and time types of values.

Syntax:

max(value1, value2...);

Parameters: It takes any number of parameters.

Return Value: This function returns the largest value from a set of comma-separated values.

Example 1: This example demonstrates the above-mentioned function when only 2 parameters are given.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, 
                   initial-scale=1.0">

    <style>
        .container {
            display: flex;
            justify-content: center;
            align-content: center;
            color: white;
            font-size: 30px;
            background-color: green;
            width: max(100px, 400px);
            height: max(100px, 400px);
        }

        p {
            align-self: center;
        }
    </style>
</head>

<body>
    <div class="container">

        <p>Geeks for geeks</p>

    </div>
</body>

</html>

Output:

Example 2: When more than two parameters are given in max() function.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, 
                   initial-scale=1.0">

    <style>
        .container {
            display: flex;
            justify-content: center;
            align-content: center;
            color: white;
            font-size: auto;
            background-color: green;
            width: max(10px, max(max(10px, 40px),
                        max(10px, 150px)));

            height: max(10px, max(max(10px, 40px),
                        max(10px, 100px)));
        }

        p {
            align-self: center;
        }
    </style>
</head>

<body>
    When nested max function is used
    <div class="container">

        <p>Geeks for geeks</p>

    </div>
</body>

</html>

Output:

Supported Browsers:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4