CSS Tutorial

The language for styling web pages.

CSS Box Model

The CSS Box Model

In CSS, every element is a box. The CSS box model is a box that wraps around every HTML element. It consists of: content, padding, border, and margin.

Box Model Layers (inside → outside):

  1. Content - The actual text/image
  2. Padding - Space between content and border
  3. Border - A line surrounding the padding
  4. Margin - Space outside the border

Tip: Use box-sizing: border-box so padding and border are included in the total width.

Try It Yourself

Edit the code below and click Run to see the result live.

Source Code
Result
Topics