box-sizing

  • Revision slug: CSS/Box-sizing
  • Revision title: box-sizing
  • Revision id: 28070
  • Created:
  • Creator: myakura
  • Is current revision? No
  • Comment 139 words added, 122 words removed

Revision Content

{{ CSSRef() }}

Summary

The box-sizing CSS property is used to alter the default CSS box model used to calculate widths and heights of elements. It is possible to use this property to emulate the behavior of browsers that do not correctly support the CSS box model specification.

  • {{ Xref_cssinitial() }}: {{ Cssxref("content-box") }}
  • Applies to: all elements
  • {{ Xref_cssinherited() }}: no
  • Percentages: n/a
  • Media: {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }}: as specified

Syntax

box-sizing:  content-box | padding-box | border-box

Values

content-box
This is the default style as specified by the CSS standard. The widthand height properties are measured including only the content, but not the border, margin, or padding.
padding-box
The widthand height properties include the padding size, and do not include the border or margin. {{ note("The value is only supported in Gecko; it hadn't been part of the CSS3-UI specification. It was later added to the spec but the current Editor's Draft marks it as being at-risk.") }}
border-box
The widthand height properties include the padding and border, but not the margin. This is the box model used by Internet Explorer when the document is in Quirks mode.

Examples

/* support Firefox, Safari/WebKit, Opera and IE8+ */

.example {
   -moz-box-sizing:    border-box;
   -webkit-box-sizing: border-box;
    box-sizing:        border-box;
}

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
prefixed support 1.0
{{ property_prefix("-webkit") }}
1.0 (1.0)
{{ property_prefix("-moz") }}
    3.0 (522)
{{ property_prefix("-webkit") }}
standard support 10
box-sizing
{{ CompatNo() }} {{ mozbug("243412") }} 8.0
box-sizing
7.0
box-sizing
5.1 (534.12)

box-sizing
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} Mango 7.5 {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}

Notes

See {{ bug("243412") }} and its dependents:

  • -moz-box-sizing doesn't apply to table cells
  • min-height/max-height does not work for -moz-box-sizing: border-box

Specifications

  • {{ spec("http://dev.w3.org/csswg/css3-ui/#box-sizing" ,"CSS3 Basic User Interface Module: box-sizing","ED") }}

See also

CSS box model

{{ languages( { "fr": "fr/CSS/box-sizing", "pl": "pl/CSS/box-sizing" } ) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h2>Summary</h2>
<p>The<code> box-sizing </code>CSS property is used to alter the default CSS box model used to calculate widths and heights of elements. It is possible to use this property to emulate the behavior of browsers that do not correctly support the CSS box model specification.</p>
<ul> <li>{{ Xref_cssinitial() }}: {{ Cssxref("content-box") }}</li> <li>Applies to: all elements</li> <li>{{ Xref_cssinherited() }}: no</li> <li>Percentages: n/a</li> <li>Media: {{ Xref_cssvisual() }}</li> <li>{{ Xref_csscomputed() }}: as specified</li>
</ul>
<h2>Syntax</h2>
<pre>box-sizing:  content-box | padding-box | border-box</pre>
<h2>Values</h2>
<dl> <dt>content-box</dt> <dd>This is the default style as specified by the CSS standard. The <code>width</code>and <code>height</code> properties are measured including only the content, but not the border, margin, or padding.</dd> <dt>padding-box</dt> <dd>The <code>width</code>and <code>height</code> properties include the padding size, and do not include the border or margin.
{{ note("The value is only supported in Gecko; it hadn't been part of the CSS3-UI specification. It was later added to the spec but the current Editor's Draft marks it as being at-risk.") }}</dd> <dt>border-box</dt> <dd>The <code>width</code>and <code>height</code> properties include the padding and border, but not the margin. This is the box model used by Internet Explorer when the document is in Quirks mode.</dd>
</dl>
<h2>Examples</h2>
<pre>/* support Firefox, Safari/WebKit, Opera and IE8+ */

.example {
   -moz-box-sizing:    border-box;
   -webkit-box-sizing: border-box;
    box-sizing:        border-box;
}</pre>
<h2 name="Browser_Compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari (WebKit)</th> </tr> <tr> <td>prefixed support</td> <td>1.0<br> {{ property_prefix("-webkit") }}</td> <td><strong>1.0</strong> (1.0)<br> {{ property_prefix("-moz") }}</td> <td> </td> <td> </td> <td><strong>3.0</strong> (522)<br> {{ property_prefix("-webkit") }}</td> </tr> <tr> <td>standard support</td> <td>10<br> <code>box-sizing</code></td> <td>{{ CompatNo() }} {{ mozbug("243412") }}</td> <td>8.0<br> <code>box-sizing</code></td> <td>7.0<br> <code>box-sizing</code></td> <td><strong>5.1</strong> (<a class="external" href="http://trac.webkit.org/changeset/71348" title="http://trac.webkit.org/changeset/71348">534.12</a>)<br> <br> <code>box-sizing</code></td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Phone</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>Mango 7.5</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> </tr> </tbody> </table>
</div>
<h2>Notes</h2>
<p>See {{ bug("243412") }} and its dependents:</p>
<ul> <li><code>-moz-box-sizing</code> doesn't apply to table cells</li> <li><code>min-height</code>/<code>max-height</code> does not work for <code>-moz-box-sizing: border-box</code></li>
</ul>
<h2>Specifications</h2>
<ul> <li>{{ spec("http://dev.w3.org/csswg/css3-ui/#box-sizing" ,"CSS3 Basic User Interface Module: box-sizing","ED") }}</li>
</ul>
<h2>See also</h2>
<p><a class="internal" href="/en/CSS/box_model" title="En/CSS/Box model">CSS box model</a></p>
<p>{{ languages( { "fr": "fr/CSS/box-sizing", "pl": "pl/CSS/box-sizing" } ) }}</p>
Revert to this revision