THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Style boxSizing Property

Style Object Reference Style Object

Example

Change the boxSizing property:

document.getElementById("myDIV").style.boxSizing = "border-box";
Try it yourself »

Definition and Usage

The boxSizing property allows you to define certain elements to fit an area in a certain way.

For example, if you want two bordered boxes side by side, it can be achieved through setting boxSizing to "border-box". This forces the browser to render the box with the specified width and height, and place the border and padding inside the box.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The boxSizing property is supported in Internet Explorer, Opera, Chrome, and Safari.

Firefox supports an alternative, the MozBoxSizing property.


Syntax

Return the boxSizing property:

object.style.boxSizing

Set the boxSizing property:

object.style.boxSizing="content-box|border-box|initial|inherit"

Property Values

Value Description
content-box Default value. This is the behavior of width and height as specified by CSS2.1. The specified width and height (and min/max properties) apply to the width and height respectively of the content box of the element. The padding and border of the element are laid out and drawn outside the specified width and height
border-box The specified width and height (and min/max properties) on this element determine the border box of the element. That is, any padding or border specified on the element is laid out and drawn inside this specified width and height. The content width and height are calculated by subtracting the border and padding widths of the respective sides from the specified 'width' and 'height' properties
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

Technical Details

Default Value: content-box
Return Value: A String, representing the box-sizing property of an element
CSS Version CSS3

Related Pages

CSS reference: box-sizing property


Style Object Reference Style Object