โ† Web & Frontend
#4 most askedVery commonEasyBox model

The CSS box model

New to Box model? Learn it from scratch first
The Box Model โ†’
๐Ÿข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

Explain the CSS box model and box-sizing: border-box.

๐ŸŽค Answer it out loud, then check yourself

Say your answer as if the interviewer is listening (30โ€“90 seconds). Then reveal what a strong answer covers and tick what you said.

    Try it ยท run and change it
    // content-box vs border-box, the arithmetic
    const width = 200, padding = 20, border = 2;
    console.log("content-box total width:", width + 2 * padding + 2 * border);
    console.log("border-box total width:", width, "(content shrinks to", width - 2 * padding - 2 * border + ")");
    
    Answer out loud first, then compare.
    Want to rehearse it?
    Answer this to the AI interviewer and get a verdict โ†’