Layout & responsive thinking
How elements arrange and reflow across screens — the box model, flexbox vs grid, reading width, mobile-first — so you can describe a layout precisely enough to build.
Layout is how the pieces are arranged and how that arrangement reflows when the screen gets narrower. You don’t need to write CSS, but you do need to describe a layout precisely — “a two-column grid that stacks on mobile, content capped at a readable width” — so the AI builds the right structure instead of guessing. This chapter is the vocabulary of arrangement. (The mechanics — how the box model and grid actually render — are Module 5.)
Inside vs between: the box model
You don’t need to write it, but you need to say it. Every element is a box: content in the middle, padding as breathing room inside the border, the border, and margin as the gap to its neighbours. When a card feels cramped, you want more padding (inside). When two cards are touching, you want more margin (between). Naming which one you mean is the difference between one precise instruction and three rounds of “a bit more space… no, the other space.”
One dimension or two: flexbox vs grid
This is the one layout decision worth knowing by name. Flexbox lays things out in a single direction — a row or a column — and is ideal when items should flow and wrap: a toolbar, a row of tags, a navbar. Grid places things in rows and columns at once and is the tool for the overall page: a fixed sidebar beside fluid content, or a responsive gallery of cards. The rule of thumb: flex for a line of things, grid for a layout of regions.
Mobile-first, and why text needs a leash
Design the narrow layout first, then use breakpoints to add columns and space as the screen grows. This beats the reverse — cramming a desktop layout onto a phone — because deciding what matters on a small screen forces real priorities, and expanding is easier than salvaging. The other half is reading width: on a wide monitor, a paragraph that spans the whole screen is exhausting to read, so cap text containers at ~65–75 characters. (This very page does exactly that — the prose has a max width while diagrams can run wider.)
Name the archetype
Most screens are one of a handful of layouts. Naming the archetype gets you a correct skeleton in one sentence.
| Archetype | Shape | Good for |
|---|---|---|
| Centered column | one capped-width column, centered | articles, forms, marketing pages |
| Sidebar + content | fixed nav beside fluid content | apps, docs (like this site) |
| Dashboard grid | a grid of cards / widgets | analytics, admin overviews |
| Master–detail | a list pane + a detail pane | email, settings, inboxes |
| Card grid | a responsive gallery of equal cards | products, galleries, search results |
01 Learning objectives
0 / 6 done02 Curated reading
03 Knowledge check
- 01easy
Padding vs margin:
- 02medium
You need a wrapping row of tags. Flexbox or grid?
- 03medium
“Mobile-first” means…
04 Interview questions
browse all ↗What gets asked on this topic — tap a card for how to approach it, the follow-ups, and the trap. Company tags are best-effort & sourced.
-
When would you reach for flexbox vs CSS grid?
Flexbox is for one-dimensional layout — a single row or column of items that flow and wrap (a toolbar, a row of tags, a navbar). Grid is for two-dimensional layout — rows and columns at once (a page's sidebar-plus-content, a gallery of cards). The rule of thumb: flex for a *line* of things, grid for a *layout* of regions. They compose, too — grid for the page skeleton, flex inside each region.
What a strong answer coversFlexbox = one axis (row or column) that can wrap.
Grid = two axes (rows and columns) for page structure.
Flex for a line of items; grid for a layout of regions.
Common pattern: grid for the page, flex inside each cell.
Follow-ups they push on- Could you build a card gallery with flexbox? What's the downside?
- Why is grid better for a sidebar + content layout?
Red flag Forcing a whole two-dimensional page layout out of nested flexboxes — grid expresses it directly and stays responsive.
source: MDN — Introduction to CSS layout ↗