The Wayback Machine - https://web.archive.org/web/20240911193939/https://www.geeksforgeeks.org/css-min-function/
Open In App

CSS min() Function

Last Updated : 30 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

min() function in CSS is used to extract the minimum value from a set of comma-separated values. It can take two parameters and a min function can be used inside another min function if the comparison is to be made between multiple values.

Syntax:

min(value1, value2);
min(value1, min(value2, min(value3, value4)));

Parameters: It takes the following parameters.

  • values: It is the set of comma-separated values from which the smallest one is extracted.

Returns: This function returns the smallest value from a set of comma-separated values.

Below given are a few examples of the above function.

Example 1:

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,
                initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    /* CSS for the html */
    * {
        font-family: 'Times New Roman', Times, serif;
        font-size: 20px;
        font-stretch: narrower;
        font-weight: 600;
    }

    .box {
        display: flex;
        color: white;
        background-color: green;
        justify-content: center;
        height: min(200px, 500px);
        width: min(200px, 500px);
    }

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

<body>
    When nested min function is not used
    <div class="box">
        <h2>Geeks for geeks</h2>
    </div>
</body>

</html>

Output:

Example 2:

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,
                initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    /* CSS for the html */
    * {
        font-family: 'Times New Roman', Times, serif;
        font-size: min(20px, 1000px);
        font-stretch: narrower;
        font-weight: 600;
    }

    .box {
        display: flex;
        color: white;
        background-color: green;
        justify-content: center;
        height: min(20vh, min(30vh, min(40vh, 50vh)));
        width: min(50vw, min(50vw, min(40vw, 50vw)));
    }

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

<body>
    When nested min function is
    used with different units
    <div class="box">
        <h2>Geeks for geeks</h2>
    </div>
</body>

</html>

Output:

Browsers supported:

  • Chrome 79 and above
  • Opera 66 and above
  • Internet Explorer not supported
  • Safari 11.1 and above
  • Firefox 75 and above
  • Edge 79 and above

CSS min() Function – FAQs

What does the min() function do in CSS?

The min() function allows you to set a value based on the minimum of two or more arguments, which can be useful for responsive designs to ensure elements do not grow beyond a certain size.

How do you use the min() function in CSS?

Use min() in CSS properties like width or height, for example: width: min(80%, 600px);, to select the smaller value between 80% and 600px.

Can min() be used with percentages and absolute units?

Yes, min() can mix different units like percentages and pixels, providing flexible options for responsive design.

What are common use cases for the min() function in CSS?

Common uses include setting maximum sizes for elements in responsive layouts, such as limiting the width of content on larger screens.

Is the min() function widely supported in CSS?

The min() function is supported in most modern browsers, providing robust functionality for contemporary web design.



Previous Article
Next Article

Similar Reads

CSS | min-inline-size Property
The CSS min-inline-size property is used to create the minimum size of an element in the direction opposite that of the writing direction. Like if the writing direction is horizontal then min-inline-size is equivalent to min-height, and if it is in vertical mode then equal to min-width. Syntax: min-inline-size: length | percentage | auto | none | m
2 min read
CSS | min-block-size Property
The min-block-size property in CSS is used to create the minimum horizontal or vertical size of an element. If the writing direction is horizontal then min-block-size is equivalent to min-height property, and if it is in vertical mode then equal to min-width property. Syntax: min-block-size: length| percentage| auto| none| min-content| max-content|
2 min read
Tailwind CSS Min-Width
This class accepts lots of values in tailwind CSS in which all the properties are covered in class form.  It is the alternative to the CSS min-width property. This class is used to define the minimum width of an element. The value of the width cannot be less than the value of the min-width. If the content specified within the element is smaller, mi
1 min read
Tailwind CSS Min-Height
This class accepts lots of values in tailwind CSS in which all the properties are covered in class form.  It is the alternative to the CSS Min-Height Property. This class is used to set the minimum height of an element. The min-height class is used when the content of the element is smaller than the min-height and if the content is larger than the
2 min read
Price Range Slider with Min-Max Input using HTML CSS and JavaScript
In this article, we are going to implement Price Range Slider using HTML, CSS, &amp; JavaScript. Here, The user can move the meter on a price range slider to choose the suitable price range. To choose the right price range, the user can use a slider or input the minimum and maximum price values. We will be using HTML to structure our project, CSS f
5 min read
CSS min-height Property
The min-height property in CSS is used to set the minimum height of an element. The min-height property is used when the content of the element is smaller than the min-height and if the content is larger than the min-height then it has no effect. This property ensures that the value of the height property is not less than the specified height value
3 min read
CSS min-width Property
The min-width property in CSS is used to define the minimum width of an element. The value of the width cannot be less than the value of the min-width. If the content specified within the element is smaller, min-width maintains the specified minimum width.  Syntax: min-width: length|initial|inherit;Property Values: length: This property is used to
3 min read
PHP min( ) Function
The min() function of PHP is used to find the lowest value in an array, or the lowest value of several specified values. The min() function can take an array or several numbers as an argument and return the numerically minimum value among the passed parameters. The return type is not fixed, it can be an integer value or a float value based on input
2 min read
Underscore.js _.min Function
The Underscore.js is a JavaScript library that provides a lot of useful functions that help in programming in a big way like the map, filter, invoke, etc even without using any built-in objects. The _.min() function is used to find the minimum element from the list passed. If an iterate is given, then it will be applied to each value and generate c
3 min read
D3.js | d3.min() function
The d3.min() function in D3.js is used to returns the minimum value in the given array using natural order. If an array is empty then it returns undefined as output. Syntax: d3.min(Array) Parameters: This function accepts a parameters Array which is an array of elements whose minimum value is to be calculated. Here elements might be integers or any
2 min read
p5.js min() function
The min() function in p5.js is used to get the minimum value from the sequence of numbers. Syntax: min(a, b) or min(arr) Parameters: The min(a, b) function accepts two parameters which are two different number and compared to get minimum value among them. The min(arr) function accepts a single parameter array. Return Value: It returns the minimum v
2 min read
Node.js MySQL Min() Function
We will be using Min() function in MySQL to get Minimum value from some particular column. Syntax: MIN(column_name) Parameters: MIN() function accepts a single parameter as mentioned above and described below. column_name: Column’s name from which we have to return the min value. Return Value: MIN() function returns the minimum value from the parti
2 min read
Tensorflow.js tf.min() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. The tf.min() function is used to calculate the minimum value from the specified Tensor across its dimension. It reduces the given input elements along the dimensions of axes. If the pa
2 min read
Less.js Math min() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. Because CSS is a dynamic style sheet language, it was chosen. Because LESS is adaptable, it works with a wide range of browsers. Only CSS that has been written and processed using the CSS pre-processor, a computer
3 min read
PHP Math Functions (is_nan, pow, sqrt, exp, log, log10, log1p, max, min, getrandmax, rand, mt_rand)
11. is_nan() : This function takes any value as argument and checks whether a value is number or not. It returns TRUE (1) if the specified value is 'not a number', otherwise it returns FALSE/NOTHING. Syntax : is_nan(value); Example : C/C++ Code &amp;lt;?php echo is_nan(234) . &amp;quot;\n&amp;quot;; echo is_nan(asin(1.1)) ; ?&amp;gt; Output : 1 Not
4 min read
HTML | DOM Input Datetime min Property
The Input Datetime min property is used for setting or returning the value of the min attribute of a datetime field. The Input Datetime min attribute returns a string that represents the minimum date and time allowed. Syntax: For returning the min property:datetimeObject.minFor setting the min property:datetimeObject.min = YYYY-MM-DDThh:mm:ssTZD Pr
2 min read
HTML | DOM Input Date min Property
The Input Date min property is used for setting or returning the value of the min attribute of a date field. The attribute returns a string that represents the minimum date allowed. Syntax: For returning the min property:inputdateObject.minFor setting the min property:inputdateObject.min = YYYY-MM-DD Property Value: YYYY-MM-DDThh:mm:ssTZD :It is us
2 min read
HTML | DOM Input DatetimeLocal min Property
The Input DatetimeLocal min property is used for setting or return the value of the min attribute of the datetimeLocal field. It is used to specify the minimum value of date and time for a datetimeLocal field. It returns a string that represents the minimum date and time allowed. Syntax: It returns the Input DatetimeLocal min property.inputdatetime
2 min read
HTML | DOM Input Number min Property
The DOM Input Number min Property is used to set or return the value of the min attribute of a number field. The min attribute defines the minimum value for a input number field. Syntax: It returns the min property.numberObject.minIt is use to set the min property.numberObject.min = number Property values: It contains a single value i.e number whic
2 min read
HTML | DOM Input Month min Property
The DOM Input Month min property in HTML DOM is used to set or return the value of the min attribute of a Month field. The min attribute specifies the minimum value of Month and year for a Month field. Syntax: It returns the min property.monthObject.minIt is used to set the min property.monthObject.min = YYYY-MM Property Values: YYYY-MM: This value
2 min read
HTML | DOM Input Week min Property
The DOM Input Week min property in HTML DOM is used to set or return the value of the min attribute of a week field. The min attribute specifies the minimum value (week and year) for a week field. Syntax: It returns the min property.weekObject.minIt is used to set the min property.weekObject.min = YYYY-WWW Property Values: YYYY-WWW: This values sta
2 min read
HTML | DOM Input Time min Property
The DOM Input Time min Property is used to set or return the value of the min attribute of a number field. The min attribute defines the minimum time for an input Time field. Syntax: It returns the min property.timeObject.minIt is use to set the min property.timeObject.min = hh:mm:ss.ms Property values: hh:mm:ss.ms - It is used to specifies a minim
2 min read
HTML | DOM Input Range min Property
The Input Range min Property in HTML DOM is used to set or return the value of min attribute of the slider control. The min attribute is used to specify the minimum value of slider control. Syntax: It returns the Input Range min Property:rangeObject.minIt is used to set Input Range min Property:rangeObject.min = number Property Values: It contains
2 min read
HTML | &lt;input&gt; min Attribute
The HTML min Attribute is used to specify the minimum value for an input field. It can be used together with the max attribute to create a range of values. It can be used with the many input fields such as number, range, date, datetime, datetime-local, month, time and week. Syntax: &lt;input min="number|date"&gt; Attribute Values: number: It contai
1 min read
HTML &lt;meter&gt; min Attribute
The HTML &lt;meter&gt; min Attribute is used to specify the lower bound of the gauge. The value of the min attribute is always less than the max attribute. It has a default value which is 0. Syntax: &lt;meter min="number"&gt; Attribute Values: number: It contains a numeric value which specify the minimum value for the gauge. Example: This Example i
1 min read
Max/Min value of an attribute in an array of objects in JavaScript
In this article, we are given an array of objects and the task is to get the maximum and minimum values from the array of objects. For this approach, we have a few methods that will be discussed below. Methods to get Min/Max values:using JavaScript apply() and Array map()using JavaScript Array reduce() Methodusing JavaScript loopsMethod 1: Using Ja
3 min read
How to Round off Time to Nearest 5 Min using JavaScript ?
Given a JavaScript date and the task is to round it to 5 minutes with the help of JavaScript. There are two approaches that are discussed below: Approach 1: In this approach, both options are available to either round down or round up the date object. This example uses basic Math.floor() function and Math.ceil() function to perform the operation. E
2 min read
Collect.js min() Method
The min() method is used to return the minimum element from the given array or collection. The method can be specified with a key as a parameter so that only the values of that key in the collection would be considered and the minimum element would be found from those values. Syntax: collect(array).min(key) Parameters: The collect() method takes on
1 min read
Fabric.js min() Method
The min() method is used to find the minimum value from the specified array. Syntax: min( array ) Parameters: This method accepts single parameter as mentioned above and described below: array: This parameter holds the array to iterate over. Return Value: This method returns the minimum value from the array. Example 1: C/C++ Code &lt;!DOCTYPE html
1 min read
jQuery UI Slider min Option
jQuery UI consists of GUI widgets, visual effects, and themes implemented using jQuery, CSS, and HTML. jQuery UI is great for building UI interfaces for the webpages. jQueryUI provides us a slider control through the slider widget. Slider helps us to get a certain value using a given range. In this article we will see how to set the min option in a
2 min read