Skip to content
Justice Tech School

The Box Model

Every element is a box made of four layers: content, padding (space inside the border), border, and margin (space outside the border).

The total space an element takes is content size plus padding, border and margin. Understanding this model is the key to controlling spacing and sizes.

Example
<style>
  .card {
    width: 200px;
    padding: 16px;
    border: 4px solid #166534;
    margin: 20px;
    background: #dcfce7;
  }
</style>
<div class="card">I am a box</div>

Exercise

Add space inside the border.

.card {
  : 20px;
}

Quiz Test

Which layer is between the content and the border?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.