For browsers that adhere to the CSS box model, the width and height of an element are calculated by adding the width/height + padding + border. So for example, if an element has its width property set to 500px, left and right padding of 10px and left and right border of 15px, then the actual rendered width of this element is 500 + 10 + 10 + 15 + 15 = 550px.

Browser Support

The box-sizing property is supported in Chrome, Internet Explorer, and Opera. Firefox supports the alternative vendor prefix property, the -moz-box-sizing property, and Safari supports the -webkit-box-sizing property.

Syntax

The box-sizing property allows you to modify the calculated width and height of an element.

Usage

The box-sizing property can be used in various situations. For example, if you need to place two boxes that include borders, side by side, it can be easily achieved by setting the box-sizing property value to border-box. This will force the browser to render the box with the specified width and height, and place the border and padding inside the box. So, in the following example, if your browser supports the box-sizing property, the two div elements will appear side by side rather than one div on top of the other.

Example

In this example, the two div elements will appear side by side since their padding and border widths are calculated within the border-box of the elements.

Results

If your browser supports the box-sizing property, you will see the two divs side by side. If not, your browser will simply use the content-box value.