STAGE 01 / LESSON 05
CSS, the box model and responsive layout
Every element is laid out as a box, and CSS controls how those boxes fit together.
THE IDEA
Understand it.
A box contains content, padding, a border and margin. With box-sizing: border-box, the declared width includes the padding and border, making component sizing easier to reason about.
Use flexible layouts such as Grid or Flexbox rather than fixed screen-sized widths. A media query can change the arrangement when space is limited; test with real content and at narrow widths.
SEE IT IN CONTEXT
A responsive task grid
.tasks {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 1rem;
}
@media (max-width: 40rem) {
.tasks { grid-template-columns: 1fr; }
}The layout uses two flexible columns on wider screens and one on narrow screens. The content remains the same.
LEARN FROM REAL WEBSITES
See it in the real world.
These simplified structures come from public sources. Company systems change, and the sources may describe only one project or an earlier design.
GOV.UK
Documentation checked November 2026A layout that adapts
The GOV.UK design system documents page widths and a responsive grid for service pages.
- Page container
- Grid columns
- Available screen width
What to learn: The container and columns control how content occupies space as the viewport changes.
Read the source: GOV.UK page layoutsShopify
Shopify engineering, 2018Tables on narrow screens
Shopify described the responsive data-table challenge for its Polaris design system and the need to preserve readable context.
- Table columns
- Narrow viewport
- Responsive table behavior
What to learn: A real layout decision must consider overflow and readability, not only making a box smaller.
Read the source: Shopify responsive data tableTRY IT YOURSELF
Practice.
Add padding and a border to a task card. What changes when box-sizing is border-box?
Show one possible answer
The declared width includes the padding and border rather than adding them outside the content width. Margin remains outside that width.
GO DEEPER