box-sizing

  • Revision slug: CSS/box-sizing
  • Revision title: box-sizing
  • Revision id: 289868
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

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
  • 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 {{ Cssxref("width") }} and {{ Cssxref("height") }} properties are measured including only the content, but not the border, margin, or padding.
padding-box
The {{ Cssxref("width") }} and {{ Cssxref("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 earlier CSS3-UI specifications and was later added to the Editor's Draft. Currently Editor's Draft marks it as at-risk for removal.") }}
border-box
The {{ Cssxref("width") }} and {{ Cssxref("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;
}

Specifications

Specification Status Comment
CSS Basic User Interface Module Level 3 {{ Spec2('CSS3 Basic UI') }}  

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 9.0
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

Currently hasn't yet dropped the -moz- prefix. 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. See {{ bug("308801") }}

See also

CSS box model

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

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary">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 class="cssprop">
  <li><dfn>{{ Xref_cssinitial() }}:</dfn> {{ Cssxref("content-box") }}</li>
  <li><dfn>Applies to:</dfn> all elements</li>
  <li><dfn>{{ Xref_cssinherited() }}:</dfn> no</li>
  <li><dfn>Media:</dfn> {{ Xref_cssvisual() }}</li>
  <li><dfn>{{ Xref_csscomputed() }}:</dfn> as specified</li>
</ul>
<h2 id="Syntax">Syntax</h2>
<pre>box-sizing:  content-box | padding-box | border-box</pre>
<h3 id="Values">Values</h3>
<dl>
  <dt>
    <code>content-box</code></dt>
  <dd>
    This is the default style as specified by the CSS standard. The {{ Cssxref("width") }} and {{ Cssxref("height") }} properties are measured including only the content, but not the border, margin, or padding.</dd>
  <dt>
    <code>padding-box</code></dt>
  <dd>
    The {{ Cssxref("width") }} and {{ Cssxref("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 earlier CSS3-UI specifications and was later added to the Editor's Draft. Currently Editor's Draft marks it as at-risk for removal.") }}</dd>
  <dt>
    <code>border-box</code></dt>
  <dd>
    The {{ Cssxref("width") }} and {{ Cssxref("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.</dd>
</dl>
<h2 id="Examples">Examples</h2>
<pre class="brush: css">/* support Firefox, Safari/WebKit, Opera and IE8+ */

.example {
   -moz-box-sizing:    border-box;
   -webkit-box-sizing: border-box;
    box-sizing:        border-box;
}</pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="external" href="http://dev.w3.org/csswg/css3-ui/#box-sizing">CSS Basic User Interface Module Level 3</a></td>
      <td>{{ Spec2('CSS3 Basic UI') }}</td>
      <td> </td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_Compatibility" 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>
          <p> </p>
        </td>
        <td> </td>
        <td><strong>3.0</strong> (522)<br>
          {{ property_prefix("-webkit") }}</td>
      </tr>
      <tr>
        <td>standard support</td>
        <td>9.0<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>
          <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>
<h3 id="Notes">Notes</h3>
<p>Currently hasn't yet dropped the <code>-moz-</code> prefix. 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>. See<code> </code>{{ bug("308801") }}</li>
</ul>
<h2 id="See_also">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