Every HTML element is a rectangular box with four layers, from inside to outside:
- Content — text, images
- Padding — space inside the border
- Border — the line around the padding
- Margin — space outside the border, between elements
Total width
By default: width + left/right padding + left/right border.
Example: width: 200px; padding: 20px; border: 5px → total 250px.
Margins add space around the box but are not part of its size. Use DevTools to see the box model of any element.
Example
Example — Box model in action
HTML
<style>
.box {
width: 200px;
padding: 20px;
border: 5px solid #1f386b;
margin: 30px;
background: #dbe8ff;
}
</style>
<div class="box">Width 200px + padding 40px + border 10px = 250px wide.</div>