Predict a box’s border-to-border width from its content, padding, border, and sizing rule.
A card can have a width of 200 pixels in the stylesheet and measure 236 pixels across on the page. To explain the difference, find the edge that the width measures.
The content box holds the card’s text or image. Padding creates space between that content and the border. If the card has a background color, you can see it behind the padding. The border encloses both regions. Margin creates space outside the border, where the card’s background stops.
To move a label away from the inside edge of a card, increase the padding. To leave space between the outside of the card and its neighbor, look at the margin. The browser inspector’s box-model diagram shows the four regions separately.
For an ordinary block using content-box, the specified width measures the content. Give the card a width of 200 pixels, 16 pixels of padding on each side, and a 2-pixel border on each side. From one border edge to the other, it measures 236 pixels. Both sides count.
With border-box, the same specified width includes the padding and border. The card measures 200 pixels across, leaving 164 pixels for the content. A line of text may wrap sooner even though all three declarations use the same numbers. Margin lies outside both measurements.
Try it yourself
HTML + CSS