Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

CSS Dictionary

  1. Home
  2. CSS Dictionary
  3. box-sizing

box-sizing

Changes the calculation method for the box model (element size).

Sample Code

div.test { box-sizing: content-box;}
div.test1 { box-sizing: border-box;}

Available Values

ValueDescription
content-boxThe size specified by the 'width' and 'height' properties does not include padding, border, or margin. This 'content-box' is the initial value.
border-boxThe size specified by the 'width' and 'height' properties includes padding and border. Margin is not included.

Browser Preview

The div elements in the samples below have 'width: 300px', 'height: 300px', 'padding: 10px', and 'border: solid 10px red' specified.

<div style="box-sizing: content-box; width: 300px; height: 300px; border: solid 10px red; padding: 10px; margin: 0 auto;">This is a div element with <span style="color: #f00">box-sizing: content-box</span>. The size specified by 'width' and 'height' does not include padding or border, so the total element size becomes 340px wide and 340px tall.</div>

<div style="box-sizing: border-box; width: 300px; height: 300px; border: solid 10px red; padding: 10px; margin: 0 auto;">This is a div element with <span style="color: #f00">box-sizing: border-box</span>. The size specified by 'width' and 'height' includes padding and border but not margin, so the element size is exactly 300px wide and 300px tall.</div>

Browser Support

Chrome Chrome
10+
9
8
7
6
5
4
3
2
↑ Requires prefix '-webkit-'
Firefox Firefox
29+
28
27
26
25
24
23
22
21
↑ Requires prefix '-moz-'
Safari Safari
5.1+
4
3
↑ Requires prefix '-webkit-'
2 and earlier ×
Edge Edge
12+
Supported in all versions
IE IE
11
10
9
8
7 ×
6 ×
Opera Opera
7+
6 and earlier ×
iOS Safari iOS Safari
6+
5
4
3
2
1
↑ Requires prefix '-webkit-'
Android Android Browser
4+
2
↑ Requires prefix '-webkit-'
Chrome Android Chrome Android
Latest
Same support as desktop
Firefox Android Firefox Android
Latest
Same support as desktop

※ Version data based on MDN / Can I Use.

Overview

Changes the calculation method for the box model (element size).

When 'content-box' is specified, the size defined by the 'width' and 'height' properties does not include padding, border, or margin. This 'content-box' is the initial value.

<div style="box-sizing: content-box; width: 300px; height: 300px; border: solid 10px red; padding: 10px; margin: 0 auto;">This is a div element with <span style="color: #f00">box-sizing: content-box</span>. Since the 10px padding and 10px border are added to the size specified by 'width' and 'height', the element becomes 340px wide and 340px tall.</div>

When 'border-box' is specified, the size defined by the 'width' and 'height' properties includes padding and border. Margin is not included.

<div style="box-sizing: border-box; width: 300px; height: 300px; border: solid 10px red; padding: 10px; margin: 0 auto;">This is a div element with <span style="color: #f00">box-sizing: border-box</span>. Since the 10px padding and 10px border are included in the size specified by 'width' and 'height', the element size is exactly 300px wide and 300px tall as specified.</div>

Regarding vendor prefixes, almost all modern browsers now support this property without any vendor prefix, so they are generally not needed. However, some older Android stock browsers may require vendor prefixes, in which case you can write it as follows.

div.test {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

If you find any errors or copyright issues, please .