Track 02 · Lesson 15 of 17Inside the browser
- 01Events and bubbling
- 02What fires when you click or type
- 03Keyboard, input and focus events
- 04Default actions and preventDefault()
- 05Event delegation
- 06Listener options and cleanup
- 07Custom events
- 08Debounce and throttle
- 09Events in React
- 10The event loop
- 11Don't block the main thread
- 12The rendering pipeline
- 13Core Web Vitals
- 14HTTP caching
- 15Responsive design
- 16SEO basics
- 17Service workers and offline
Responsive design
Lesson 15 of 17· 6 min
One page, every screen size. Layouts start with a single column for small screens and add columns as space allows, using media queries at breakpoints. Drag the width, and try a phone without the viewport meta tag.
Pour it into any glass
Drag the slider across 600px and 960px
Summer reading
Big stories for long evenings.
/* Mobile first: one column by default */ .grid { display: grid; grid-template-columns: 1fr; } .nav { display: none; } @media (min-width: 600px) { .grid { grid-template-columns: repeat(2, 1fr); } .nav { display: flex; } } @media (min-width: 960px) { .grid { grid-template-columns: repeat(3, 1fr); } }
At 375px the page shows 1 column and a menu button. Drag the slider to cross a breakpoint.
Mobile first#
Write the CSS for the smallest screen first: one column, a menu button, nothing fancy. Then add @media (min-width: …) rules that add columns and features as space grows. Starting small keeps phones fast, because they never download or undo styles meant for big screens.
The one line you can't forget#
Without <meta name="viewport" content="width=device-width, initial-scale=1">, phones assume the page was built for a desktop, lay it out about 980 pixels wide, and shrink the result to fit. Everything becomes tiny. Tick the box in the demo to see it.
Media queries versus container queries#
A media query asks how big the screen is. A container query, @container, asks how big the component's own box is, so a card can switch layout whether it sits in a wide main column or a narrow sidebar. The demo's mini page is built with container queries.
Check yourself