Go Back

CSS Section 3

Box Model

The box model is the idea that everything in CSS is essentially a box (search for "CSS Box Model" on Google).

Each box consists of the following parts: content, padding, border, margin, width, and height.

Width & Height

These properties control the size of the content area.

Border

Borders define the edge around the padding. Important border-related properties:

You can combine the above using the shorthand border property.

If you use box-sizing: border-box;, padding and border will be included inside the width and height.

Padding

Padding is the space between the content and the border.

You can use the shorthand padding or specific sides like padding-left, padding-right, etc.

Margin

Margin is the space outside the border — the distance between this element and others.

Display Property

Some elements are inline, others are block. The display property controls this behavior:

CSS Units

Next: Section 7