Skip to: content, navigation

-moz-box-sizing (CSS property)

Browser support full matrix
IE7 FF1+ Saf3 Op9.5
None Full None None
Spec
Inherited Initial Version
No content-box CSSN/A

Example

This rule will cause the browser to render the .example element using the padding-box box sizing model:

.example {
  -moz-box-sizing: padding-box;
}

Try it yourself!View all demos

Description

This property can be used to specify the CSS box model that’s used to calculate the widths and heights of elements. -moz-box-sizing is similar to the CSS3 proposal called box-sizing but, again, exhibits differences: the CSS3 proposal doesn’t include the value padding-box.

In the following example, we specify that the border-box box model is to be used to calculate the dimensions of matching elements, where the padding and borders will be included within the dimensions, rather than added to them:

.example {
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  width: 200px;
  height: 120px;
  padding: 30px;
  border: 5px solid #000;
  background: #ffffcc;
  text-align: center;
}

The results of the CSS above can be seen in Figure 1.

Figure 1. Mozilla border-box dimensions A box sizing diagram illustrating that the border-box box model
          includes the border width and padding within the specified
          dimensions of the box rather than increasing them. Instead the
          dimensions of the available content area are reduced.

As you can see, the padding and borders have not added to the element’s overall width or height. Instead, the content area has been reduced by the size of the padding. The result is the same behavior that Internet Explorer versions 6 and 7 exhibit while in quirks mode, and that Internet Explorer for Windows versions 5 and 5.5 will display at all times. There are merits in both box models, as we’ve already discussed in The Internet Explorer 5 Box Model.

box-sizing in Other Browsers

Opera, since version 8.5, has supported the CSS3 box-sizing property. Safari 3 supports the -webkit-box-sizing property, which matches the specifications for the CSS3 property.

Value

content-box
If this value is specified, the width and height properties represent only the dimensions of the content—they don’t include the border, margin, or padding. This reflects the default CSS2 box model.
padding-box
If the value padding-box is specified, the width and height properties include the padding size with the content dimensions, but don’t include the border or margin. This value isn’t included in the CSS3 box-sizing property specifications.
border-box
If the value border-box is specified, the width and height properties represent the sum of the padding size, border size, and the content dimensions, but don’t include the margin. This box sizing model reflects the IE5 box model.

Compatibility

IE5.5None
6.0None
7.0None
Firefox1.0Full
1.5Full
2.0Full
Safari1.3None
2.0None
3.0None
Opera9.2None
9.5None

This is a proprietary Mozilla extension to the CSS standard.

User-contributed notes

There are no comments yet.

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

The Principles of Beautiful Web Design

Best Seller!

You don’t need to go to Art School to design great looking web sites!

Book Cover: The Principles of Beautiful Web Design

Download the FREE sample chapters