Intern Track Roadmap

CSS box model

This course covers the CSS box model: the rectangle every rendered element occupies and its four nested layers of content, padding, border and margin. It explains how box-sizing decides what width and height measure, how the padding and margin shorthands read one to four values, and how border width, style, color and radius work. It also covers negative margins, centering with margin auto and the rules of vertical margin collapsing. The final lesson builds a styled card that uses every layer.

What you'll learn

  • ✓The four layers of the box model and how DevTools displays them
  • ✓How content-box and border-box change width and height calculations
  • ✓Padding and margin shorthands with one to four values, plus per-side properties
  • ✓Border width, style, color and rounded corners with border-radius
  • ✓Negative margins and horizontal centering with margin: 0 auto
  • ✓When adjacent vertical margins collapse and when they do not
Free preview · Lesson 1 3 min read

The box model, piece by piece

Round buttons, circular avatars and diagonal banners don't change the fact underneath. Every element a browser renders occupies a rectangular box. A <p>, a <button>, an <img> and a whole <article> each get a box. CSS's rules for sizing, spacing and positioning are rules about how that box behaves.…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...