CSSbox-sizing Property
Example
Include padding and border in the element's total width and height:
#example1 {
box-sizing: border-box;
}
Try it Yourself »box-sizing: border-box;
}
More "Try it Yourself" examples below.
Definition and Usage
Thebox-sizing property defines how the width and height of an element are calculated: should they include padding and borders, or not.
| Default value: | content-box |
|---|---|
| Inherited: | no |
| Animatable: | no.Read aboutanimatable |
| Version: | CSS3 |
| JavaScript syntax: | object.style.boxSizing="border-box"Try it |
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
| Property | |||||
|---|---|---|---|---|---|
| box-sizing | 10 | 8 | 29 | 5.1 | 9.5 |
CSS Syntax
box-sizing: content-box|border-box|initial|inherit;
Property Values
| Value | Description | Demo |
|---|---|---|
| content-box | Default. The width and height properties (and min/max properties) includes only the content. Border and padding are not included | Demo ❯ |
| border-box | The width and height properties (and min/max properties) includes content, padding and border | Demo ❯ |
| initial | Sets this property to its default value.Read aboutinitial | |
| inherit | Inherits this property from its parent element.Read aboutinherit |
More Examples
Example
Specify two bordered boxes side by side:
div {
box-sizing: border-box;
width: 50%;
border: 5px solid red;
float: left;
}
Try it Yourself »box-sizing: border-box;
width: 50%;
border: 5px solid red;
float: left;
}
Related Pages
CSS tutorial:CSS Box Sizing
HTML DOM reference:boxSizing property

