CSS box-sizing Property

❮ Previous Reference Next ❯

Example

#example1 {
  box-sizing: content-box; 
  width: 300px;
  height: 100px;
  padding: 30px;  
  border: 10px solid red;
}

#example2 {
  box-sizing: border-box;
  width: 300px;
  height: 100px;
  padding: 30px;  
  border: 10px solid red;
}





Hello World!

Meaning

The box-sizing property sets how the total width and height of an element is calculated.

learn more about box sizing in CSS Box Sizing chapter.

Default value:content-box
Inherited:No
Animatable:No
Version:CSS3
JavaScript syntax:
object.style.boxSizing="content-box|border-box|initial|inherit|revert|revert-layer|unset";



Standard Syntax

box-sizing: content-box|border-box|initial|inherit|revert|revert-layer|unset;



Browser Support

The numbers in the table specify the first browser version that fully supports the property.




Status







Property Values

The following table describes the values of this property.

Value Description
content-box Default. The width and height properties (and min/max properties) includes only the content (ie. Border and padding are not included).
border-box The width and height properties (and min/max properties) includes content, padding and border.
initial Sets this property to its default value.
inherit If specified, the associated element takes the computed value of its parent element animation-delay property.
revert Reverts the cascaded value of the property from its current value to the value the property
revert-layer Rollback styles to the ones specified in previous cascade layers.
unset Resets a property to its inherited value if the property naturally inherits from its parent, and to its initial value if not.



Default CSS Property Values

selectors {
  box-sizing: content-box;
}



More Example

The following example will set box-sizing: border-box; to all elements using universal selector:

Example

* {
  box-sizing: border-box;
}

h2, p, div {
  width: 300px;
  height: 100px;
  padding: 30px;  
  border: 4px solid red;
}
❮ Previous Reference Next ❯