</> Code Corner

CSS · CSS Tutorial · Lesson 12

CSS Box Model

Content, padding, border and margin.

Every HTML element is a rectangular box made of: content, padding, border and margin.

Example

<style>
div {
  width: 300px;
  border: 15px solid green;
  padding: 50px;
  margin: 20px;
  background: #f1f1f1;
}
</style>
<div>Total width = 300 + 50*2 + 15*2 = 430px (plus 20px margins)</div>

Total element width = width + left padding + right padding + left border + right border.

Keep reading “CSS Box Model”

Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.

Chat with us 👋