Skip to the page

The cascade and the box · core

The box model and box-sizing

Every element is a box of content, padding, border and margin; with box-sizing: border-box the width includes padding and border, which is why most resets use it.

The notes

What you must know

  • content-box (default): width = content only; padding and border add to it. border-box: width includes padding and border.
  • Vertical margins between blocks collapse (the larger wins); not in flex or grid containers.
  • display: block vs inline (ignores width/height and vertical margins) vs inline-block.
  • Percent padding is relative to the container's width, even for top and bottom.

The red pen

Common traps: mistake → fix

  • Mistake: "margins always add up"

    Fix: adjacent vertical margins of blocks collapse.

Easy to hard

Questions interviewers ask, easy to hard

  1. Explain the box model and box-sizing.
  2. What is margin collapse and when doesn't it happen?
  3. inline vs inline-block?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview