"Box model" is what @K.Daniek describes above. However, I have the impression that you want to know which of all these parameters are included in the defined width. This depends on the used box-sizing
:
The default is content-box: Here everything adds up: width plus borders plus padding make up the visible outside width of the box (if it's made visible by a border and/or background). The margins are extra - the outside distance to the parent element. (there is the special case collapsing margins, which is an extra thing) So the given width includes nothing else.
With border-box, The given width includes the border and the padding. Again, margins are extra/outside.
With padding-box, The given width includes only the padding, but not the borders. And once more, margins are extra/outside, which they are always (in relation to the defined width
).
See also the examples below, which all have the same settings for width, border, padding and margin, but the three different box-sizing
possibilities:
body {
background: #fc7;
margin: 0;
}
#x {/*200px + 2px border + 10px padding = 212px width plus margins */
box-sizing: content-box;
border: 1px solid black;
height: 200px;
margin: 2px;
padding: 5px;
width: 200px;
background: #7fc;
}
#y {/*200px = 200px width plus margins */
box-sizing: border-box;
border: 1px solid black;
height: 200px;
margin: 2px;
padding: 5px;
width: 200px;
background: #f6f;
}
#z {/*200px + 2px border = 202px width plus margins */
box-sizing: padding-box;
border: 1px solid black;
height: 200px;
margin: 2px;
padding: 5px;
width: 200px;
background: #cf9;
}
<div id="x">content-box</div>
<div id="y">border-box</div>
<div id="z">padding-box</div>