The CSS Box Model is one of the most fundamental concepts in web design. It defines how every HTML element is built: content, padding, border, and margin together form the box around the element.
The Box Model consists of four main parts: content, padding, border, and margin. Together these determine the total size and placement of the element.
In the following example, a <div> element is displayed with padding, border, and margin settings:
The following examples illustrate how padding, border, and margin values change the appearance of an element.
By default, width and height only apply to the content, and padding and border are added. With the <box-sizing: border-box;> setting, padding and border are included within the defined dimensions.
Selected: padding (1/4)
div {
width: 200px;
padding: 20px;
padding: 5px solid black;
margin: 10px;
}Move the slider to set the value, then check your answer.
Proper use of the Box Model is essential for precise layout. The following tips help:
✨ Ask Lara — your AI study partner
Unlock personalized learning support. Lara can explain lessons, summarize topics, and answer your study questions — available from the Go plan and above.
Lara helps you learn faster — exclusive to ReadyTools Go, Plus, and Max members.