boxSizing Property - Javascript CSS Style Property

Javascript examples for CSS Style Property:boxSizing


The boxSizing property sets elements to fit an area in a certain way.

Property Values

Value Description
content-box Default value. Set drawing area to content box
border-box Set the drawing area to cover border
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

Technical Details

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

Change the boxSizing property:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
div.container {/*from  w ww .j a  va  2  s . c  o  m*/
    width: 300px;
    border: 1px solid blue;
} {
    width: 150px;
    border: 3px solid red;
    float: left;
    padding: 10px;

<div class="container">
<div class="box" id="box1">This is BOX1.</div>
<div class="box" id="box2">This is BOX2.</div>
<div style="clear:both;"></div>

<button onclick="myFunction()">Test</button>

function myFunction() {
    document.getElementById("box1").style.MozBoxSizing = "border-box"; /* Code for old Firefox */
    document.getElementById("box2").style.MozBoxSizing = "border-box"; /* Code for old Firefox */
    document.getElementById("box1").style.boxSizing = "border-box";
    document.getElementById("box2").style.boxSizing = "border-box";


Related Tutorials