Frontend development

Stage 1 · Lesson 5 of 9

The box model, the cascade and specificity

How the web works, HTML and CSS

Every element is a box made of layers: the content, then padding, then a border, then margin outside it. This is the . By default, width sets only the content, so padding and border are added on top.

That is why most projects set box-sizing: border-box, which makes width include them. Sizes can be fixed pixels or such as rem, which grow with the user's font size. The decides which rule wins when several apply to the same element.

It looks at and importance first, then specificity (an id beats a class, and a class beats an element name), then source order, where the later rule wins. Most "CSS is broken" moments are one of two things: a box larger than you expected, or a rule overridden by something more specific. Open , select the element, and read its computed box and the crossed out rules.

Common trapfixing conflicts with !important, which only starts an arms race.

A question to check yourself, an AI practice session and 3 cheat sheet entries come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • CourseFree
    The Odin Project

    The Odin Project · Beginner

    Foundations course: HTML, CSS and the web built in your own editor, not a sandbox

  • GuideFree
    web.dev

    Google · Intermediate

    Free Learn HTML, Learn CSS and Learn Accessibility courses explain the why behind layout

Practise

  • Real designs to rebuild, which is where CSS layout finally sticks

Keep handy

  • The reference for every HTML element and CSS property, with browser support notes

  • Quick syntax lookups and try it editors when you only need a reminder

Also worth your time

Mark this stage as not done?