Aller au contenu principal

Box Model Math Before Pixel Nudging

Use the CSS box model to reason about element size and spacing.

html-css-basics5 min read

A CSS box is four layers, not one width. The four layers The content box holds the actual text or media. Padding is space inside the element around the content. Border sits around padding. Margin is space outside the element that separates it from neighbors. When layout breaks, the first question is which layer is responsible. Why width surprises people In the default content-box model, width applies to content only. Padding and border are added afterward. That means a card with width: 300px and padding: 20px is wider than 300px. With box-sizing: border-box, the declared width includes content, padding, and…

Read the full lesson

Sign up free: one personalized lesson every day, matched to your role and goals.

← Back to library

Nous contacter