The Box Model

The Box Model represents how the browser sees your content. According to the model, content is inside, padding is used to move content away from the edges of the box, border is used to add an outline to the box, margin is used to move the box around in space

Below is a diagram of the box model

The Box Model Diagram

Examples of A Box Model in action

example 1: Adding border and padding to a box....

Box 1

Example 2: Adding only border/padding to one direction of a box...

Box 2

Example 3: Shorthand code for padding/margin on a box...

Box 3

In shorthand code, the first number reresents the top and bottom. The second number represents left and right.

Example 4: Shorthand code, the first number represents top and bottom. The second number represents left and right.

Box 4

In shorthand code, the first number is the top, the right, then bottom, then left. In other words, clockwise.