HTML and CSS · lesson 16 of 30 · free

The box model — HTML and CSS for kids

Every element is a box. In the middle is the content, with the width you set. Around it is the padding (space inside the border), then the border (the line), then the margin (space outside that pushes other boxes away). With the usual box model, padding, border and margin are added on both sides, so the total width is width plus two paddings, two borders and two margins.

▶ Watch how it works

Got it? Practise ↓

Code tip

Inside out, twice — “add padding, border and margin on both sides of the content”

  1. From the inside out: content → padding → border → margin.
  2. Border to border = width + 2 × padding + 2 × border.
  3. Total space = width + 2 × padding + 2 × border + 2 × margin.

Use it for: Working out why a box is wider than expected and fitting boxes side by side.

Worked example: 📦 How much space across (px) does this box take in all, margin included?
.box {
  width: 210px;
  padding: 10px;
  border: 2px solid black;
  margin: 15px;
} → 264

  1. Each side has padding, border and margin: 2 × 10 + 2 × 2 + 2 × 15 = 20 + 4 + 30.
  2. 210 + 20 + 4 + 30 = 264.

Check: 264 − 30 − 4 − 20 = 210 ✓

▶ Watch it animated

✏️ Practice

Work it out in your head or on paper, type the answer and press Check. Stuck? Press “Show me how”.

Right: 0 · Tried: 0

🏁 Lesson 16 test

20 questions. Check each answer, then go to the next one. Get 16 or more right to pass.

🏅 Sign in with Google to earn the 📦 Box Model Master badge when you pass — and a certificate when you finish all 10 lessons of Part 2 · CSS. You can still take the test without signing in.

🖨️ CSS Worksheet: Box Model

✨ Free AI tutor

Ask the AI tutor about this lesson

Why does it work? When should you use it? Ask in English, मराठी or हिंदी.

Sign in with Google to ask Free — 20 questions a day.

👩‍🏫 HTML and CSS classes near you — online or at home

Prefer a real teacher? TalentJR teachers take live online classes anywhere in India and visit homes in selected cities. Tell us what you need and our team will call you with timings and fees.

Live online classesSmall groups or 1:1 with a teacher, from home, any city.
Teacher at homeA TalentJR teacher visits your home (selected cities).
At a centreClasses at a TalentJR partner centre near you, where available.
Badges, certificates & gifts A badge for every lesson you pass, a certificate for every part you finish, plus TalentJR Points for daily practice. Computer worksheets Flowcharts, block coding, spreadsheets and safe internet.