What is the CSS box model?

Every HTML element is a box with four layers, from inside to outside: content, padding, border and margin.

.box {
  width: 200px;
  padding: 20px;
  border: 5px solid #333;
  margin: 10px;
}

With the default content-box, the real width of this box is 200 + 40 (padding) + 10 (border) = 250px. With box-sizing: border-box, it is 200px. See CSS Box Model.


Learn more about the similar topics:
Tutorials
CSS Borders
Rounded Corners in CSS
CSS Height and Width
CSS Padding
CSS Margins
CSS Box Model
CSS Outline
Exercises & Assignments
Write CSS to create a box with border, padding and rounded corners
Write CSS to create a circle and a pill-shaped button
Write CSS to style a login form
Interview Questions & Answers
What is the CSS box model?
What is the difference between margin and padding in CSS?
What is box-sizing: border-box in CSS?