CSS layout that scales

Flexbox, Grid, container queries, logical properties, design tokens. Interviewers can smell an engineer who fears CSS from the first div.

About 24 min read3-question knowledge check

The mental model

CSS layout is a **constraint negotiation between parent and children**, not a set of pixel instructions. The parent proposes available space; children declare their sizing preferences (min-content, max-content, flex factors, track definitions); the engine resolves the constraints into geometry. You don't place boxes — you describe the rules, and the browser solves them for every viewport, font size, translation length, and zoom level at once.

Two analogies that stick. **Flexbox is a bench of passengers**: one row, and a negotiation over sharing it — each passenger has a preferred width (flex-basis), a willingness to spread out when there's room (flex-grow), and a tolerance for squeezing when there isn't (flex-shrink). The bench decides nothing about the row behind. Grid is city planning: the parent draws a two-dimensional map of plots (tracks) first, and children occupy plots — the map exists before the buildings, so rows and columns stay aligned regardless of what any single child contains.

Why these systems exist: before them, layout was floats and absolute positioning — tools designed for magazine text-wrap and overlays, abused for page structure. Every design change meant fragile pixel math; content of unexpected length broke everything. What breaks without modern layout isn't aesthetics — it's resilience: real content (long German words, user-generated titles, 200% zoom, RTL languages) destroys hand-positioned layouts, and interviewers can smell an engineer who fears CSS from the first div because that fear produces JavaScript doing the browser's job, badly.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision