Open In App

How do min-content and max-content work ?

CSS (Cascading Style Sheets) is a stylesheet language used to design a webpage to make it attractive. The reason for using this is to simplify the process of making web pages presentable. It allows you to apply styles on web pages. More importantly, it enables you to do this independent of the HTML that makes up each web page. 

In this article, we will learn how to do CSS min-content and max-content properties work.



min-content and max-content properties:

min-content and max-content are the value of the width property. When we define any element with this property, then it will affect that particular element. 



Approach:

Example 1: In the below code, we will see the use of min-content and how it works.




<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content=
"width=device-width, initial-scale=1">
    <title>GeeksforGeeks</title>
      
    <style>
        .card{
            width:min-content;
            border:1px solid black;
        }
    </style>
</head>
  
<body>
    <center>
        <h1 style="color:green;font-size:30px;">
            GeeksforGeeks
        </h1>
        <div class="card">
             <img src=
             alt="GFG image" /> 
             <h1>GeeksforGeeks is a computer science portal for geeks</h1>
        </div>
    </center>
</body>
</html>

Output:

min-content

Example 2: In the below code, we will see the use of the CSS max-content property and how it works.




<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content=
"width=device-width, initial-scale=1">
    <title>GeeksforGeeks</title>
      
    <style>
        .card{
            width:max-content;
            border:1px solid black;
        }
    </style>
</head>
  
<body>
    <center>
        <h1 style="color:green;font-size:30px;">
            GeeksforGeeks
        </h1>
        <div class="card">
            <img src=
                 alt="GFG image" /> 
            <h1>GeeksforGeeks is a computer science portal for geeks</h1>
        </div>
    </center>
</body>
</html>

Output:

max-content


Article Tags :