See every element as a box with padding, a border and a margin, and find out that width sets only the content.
Cards, buttons, menus and photos on every website are boxes, sized and spaced with the same few parts.
Every element on a page is a box, and CSS sets how much room each box has inside it and around it.
Make your prediction first. Help opens once you've locked it in.
<style>
.card {
width: 200px;
padding: 20px;
border: 5px solid navy;
}
</style>
<div class="card">Owls: 12 points</div>
width sets how wide a box is, padding adds space inside its border, and border draws the line. Read the code. How wide is the whole card?
How wide is the card on the page, from the outside of its border on the left to the outside on the right, in pixels?
The Box model view is on: point at the card. Blue is the content, green the padding, gold the border, and the label shows the sizes. Compare the width with your prediction. Then change padding to 40px and point at it again, and add margin: 20px; to see the orange margin.
| Code | What it does | Why |
|---|---|---|
width: 200px; |
Sets how wide the content is | It sets only the words' area. Padding and border are added outside it, on both sides, so the card is wider than 200 |
padding: 20px; |
Adds room inside the border, around the content | It is part of the box, so the background colour fills it. 20 on each side adds 40 |
border: 5px solid navy; |
Draws a line around the padding | Thickness, style and colour in one line. 5 on each side adds 10 |
margin: 20px; |
Adds space outside the border, between boxes | It is outside the box, so it is not part of the card's width and has no background |
20px with its px |
Every size needs a unit | Without one, such as padding: 20;, the browser ignores the line and shows no error |
<style>
.card {
width: 200px;
padding: 20px;
border: 5px solid navy;
}
</style>
<div class="card">Owls: 12 points</div>
The picture shows the first card in the Box model view: orange margin, gold border, green padding, blue content.
<style>
.card {
width: 180px;
padding: 15px;
border: 4px solid teal;
margin: 16px;
background-color: lightyellow;
}
</style>
<div class="card">Owls: 12 points</div>
<div class="card">Hawks: 9 points</div>

The first card's rule is width: 180px; padding: 15px; border: 4px solid teal; margin: 16px;.
The words are squashed against the border.

This card should have room inside its border.
In the picture, how wide is the first card on the page, outside border to outside border, in pixels?
The border shows, but the words are squashed against it: the padding does nothing, and there is no error. Click the line that causes it.
Give the cards 12px of padding.
Add padding: 12px; inside the .card rule.

Space the cards apart with 16px of margin.
Margin is outside the border: margin: 16px;

Make each card's content 200px wide. How wide is each card now? Point at it to check.
width: 200px; Remember that padding and border are added to it.

Give the cards 12px of padding.
This ticks when your page has all of the above.
Space the cards apart with 16px of margin.
This ticks when your page has all of the above.
Make each card's content 200px wide.
This ticks when your page has all of the above.
Both tags are span elements in one line of text.
<style>
.tag {
width: 120px;
padding: 8px;
border: 2px solid teal;
}
</style>
<p>Today: <span class="tag">Owls</span> <span class="tag">Hawks</span></p>
Make a card for a house or a club: a <div> with a heading, a picture and a line of text, styled with padding, a border, margin and a width. Point at it with Box model and work out its width before you check.
A card is one box that holds the heading, the picture and the line of text. Build the box first, then style it.
Start with a <div class="card"> holding an <h2>, an <img> and a <p>.
Then a <style> block with a .card rule: padding, border, margin and width.

Make a card with a heading and a picture, styled with padding, a border and a width.
This ticks when your page has all of the above.
Students see every element as a box of content, padding, border and margin, and find out that width sets only the content, so padding and border make the box wider. About 45 minutes.
Open the teacher guide: answers, solutions, slides and a worksheet.
Read the unit primer "CSS in 5 minutes" (the box paragraph), then make the Make task's card yourself and point at it with Box model on.
The Box model view (a button in the HTML playground) works like the browser's developer tools: point at any box to see its margin (orange), border (gold), padding (green) and content (blue), with sizes. It never changes the page. The Boxes button is different: it adds space to show nesting, so use Box model in this lesson.
The one idea: width sets the content only. The box on the page is the width plus the padding and border on both sides. Real sites often set box-sizing: border-box so that width includes padding and border; mention it once, after students are comfortable with the sums.
Working out that padding and border add to the width. Ask for the sum on paper first (200 + 20 + 20 + 5 + 5), then check it with Box model.
Stretch: Use different padding on each side (padding: 10px 30px;) and predict the width before pointing at it. Then add border-radius: 12px; for rounded corners.
Support: Give students the Modify starter with Box model on and ask them only to add padding, then margin, pointing at the card after each.
Next lesson is a review of the unit on a whole newsletter page: reading a longer stylesheet and turning the articles into cards. Class idea: measure a real website's buttons with the browser's developer tools (right-click, Inspect).