Glossary
Glossary Box model

Box model

Also known as: css box model, box-sizing, border-box, content-box
TechHTMLCSS

Definition

CSS’s account of what an element occupies: a content box, padding around it, a border around that, and margin outside — with box-sizing deciding whether a declared width means the content alone (content-box, the default) or content plus padding and border (border-box, what every reset sets), and margins that collapse between vertical neighbors

The first thing CSS teaches and the last thing it stops surprising people with. border-box everywhere is the modern default — Tailwind’s preflight sets it — so a w-64 is 16rem outside the border, which is what anyone means. Margin collapse is the other half: two stacked paragraphs with margin: 1rem are 1rem apart, not 2, until a flex or grid container turns collapsing off, which is one reason layouts feel different inside display: flex. gap exists so that spacing between siblings never has to be a margin at all.

Tech

Every element is four nested rectangles, and every layout bug is a disagreement about which one a number applies to. border-box ends most of the disagreements; gap ends most of the rest.

Related Terms

  • a: Appearance
  • ?: Keyboard shortcuts