freecoding.school100% FREE · NO SIGNUP
Cascade FallsISSUE #22 of 33

box model · content · padding · border · margin

StylaVSThe Specificity Sphinx
Styla saysThe box model: every element is content + padding + border + margin, nested like an onion.

An element's rendered size is its content box plus padding plus border (margin sits outside). By default width sets just the content box, so padding and border make the element bigger than the width you set — the classic source of layout math headaches.

Power-ups you unlock

The Specificity Sphinx attacks — common mistakes

Boss battleSet a box to width 200px with 20px padding and a border; measure the actual width in DevTools.

Example code

<!doctype html><html><head><meta charset="utf-8">
<style>.b{width:200px;padding:20px;border:5px solid #b388ff;background:#140a28;color:#e6e0ff}</style></head><body style="background:#06040d;padding:20px"><div class="b">200 + 40 + 10 = 250px wide</div></body></html>
▶ Open the interactive comic issue
‹ Height And Width · Sizing BasicsBox-Sizing · The Border-Box Swap ›