03.05 · CSS properties / Practice · At your pace
Measure the CSS box model
Separate content, padding, border and margin before choosing dimensions.
Activity 5 of 7 in CSS properties

Explore the layers before you code
Start with padding, then add a border and margin. Compare the CSS values, colored diagram and width calculation. Choose Sizing to see what changes when the same width uses border-box.
EXPLORE THE BOX MODEL
One box. Four layers.
Change one value and connect the CSS to the space it creates.
Padding creates room inside the border, around your content. Move the padding control and watch the inside space grow.
The declared height stays at 96px. Values are CSS pixels.
Diagram scales to fit. Colors identify the layers; they are not background-color declarations. Measurements remain actual CSS values.
- Content
- 180 × 96px
- Border box
- 204 × 120px
- With margins*
- 204 × 120px
.card { box-sizing: content-box; width: 180px; height: 96px; padding: 12px; border-width: 0px; border-style: solid; margin: 0px;}180 content + 12 left padding + 12 right padding = 204px border box.
Margins are outside the border box.
*With margins shows the arithmetic space allocation for this isolated box. Vertical margins between blocks can collapse, so this is not a promise that all page gaps add together.
Explore freely. This demo does not change your saved exercise code or mark the lesson complete.
Understand the change
The content box holds text or an image. Padding is inside the border; margin is outside. With content-box, a 200px width plus 20px padding and 4px border on each side totals 248px. With border-box, those parts fit inside the declared 200px.
.card {
box-sizing: border-box;
width: 200px;
padding: 12px;
border: 4px solid navy;
}What to try and where to look
Open the practice workspace and follow its checklist in the named files. Keep the supplied content and compare your result in the preview before checking your work.
YOUR TURN
Measure the CSS box model
Work through the checklist in styles.css. Run the preview, then check your work.
- In
styles.css, add a rule with selectorbodyoutside all media blocks, directly below theSTYLE BODYcomment. - Set its
font-familyproperty toArial, sans-serif. - Set its
marginproperty to24px. - Set its
line-heightproperty to1.5. - In
styles.css, add a rule with selector.cardoutside all media blocks, directly below theSTYLE CLASS CARDcomment. - Set its
box-sizingproperty toborder-box. - Set its
widthproperty to200px. - Set its
paddingproperty to20px. - Set its
borderproperty to4px solid navy. - Set its
marginproperty to16px. - Keep the supplied page content, classes, IDs and link destinations unless a checklist item explicitly changes them.
Edit styles.css and watch the preview update after you pause typing. Open index.html to inspect its stylesheet link. Run or Check saves immediately. Word wrap is enabled.
Ready to checkRun the checks to see your results here.
Your check results
Need a nudge?
Start with the target
The content box holds text or an image. Padding is inside the border; margin is outside. With content-box, a 200px width plus 20px padding and 4px border on each side totals 248px. With border-box, those parts fit inside the declared 200px.
Make one change at a time
Find the selector for the element named in the requirement. Add one declaration, run the preview and inspect the result. Check the requirement list before moving on.
One possible solution
Your code may look different and still be correct. Compare the approach with your own.
The content box holds text or an image. Padding is inside the border; margin is outside. With content-box, a 200px width plus 20px padding and 4px border on each side totals 248px. With border-box, those parts fit inside the declared 200px. Set the card to border-box with width 200px, padding 20px, border 4px solid navy and margin 16px. The measured outer border width should be 200px; the margin adds separation but is outside that width.
/* STYLE BODY */
body {
font-family: Arial, sans-serif;
margin: 24px;
line-height: 1.5;
}
/* STYLE CLASS CARD */
.card {
box-sizing: border-box;
width: 200px;
padding: 20px;
border: 4px solid navy;
margin: 16px;
}
7 days freeTry The Code Zone
THE CODE ZONE COMMUNITY
Your next step is easier together.
Try the community free for 7 days.
No charge during your trial. Choose your plan on Skool.
- Ask questions and get support in the community
- Watch every course video walkthrough
- Find a study buddy in the 24/7 study room
Make the most of your trial with Premium.
Choose Premium on Skool to try Thursday live help sessions. Bring your questions, work through code, and get unstuck together.
Scheduled Thursdays in Eastern Time. Check the Skool calendar for your local date and time.
Have a website account? Sign in