Open In App

What is the use of box-sizing property in CSS ?

In this article we will learn about to use of the box-sizing property in CSS, The box-sizing property defines how the width and height of an element should be visible to the user i.e. border and padding are to be included or not.

Syntax:



box-sizing: content-box|border-box;

Property Values:

Syntax: 



box-sizing: border-box;

Dimensions of the element are calculated as:

width = border + padding + width of the content  
height = border + padding + height of the content

Example: In this example, we using the above-explained method.




<!DOCTYPE html>
<html>
<head>
    <title>box-sizing Property</title>
 
    <style>
        div {
            width: 200px;
            height: 100px;
            padding: 20px;
            border: 2px solid orange;
            background: green;
            color: white;
            display: inline-block
        }
         
        .box {
            box-sizing: border-box;
        }
    </style>
</head>
 
<body style="text-align:center;">
    <h2>{box-sizing: border-box;}</h2>
    <br>
    <div class="box">GeeksforGeeks</div>
</body>
</html>

Output:

The following figure illustrates the {box-sizing: border-box:} for the above example.

Browser Support: The browser that fully supports box-sizing property are listed below –


Article Tags :