Responsive Architect — CSS

Design layouts for every device: 24 levels of media queries, clamp and container queries. A responsive design game for understanding modern breakpoints.

What you learn in this game

Viewport units are sizes relative to the browser's screen size. vw (viewport width) means a percentage of the screen width. For example, 50vw = half the screen width, no matter how wide the screen is.

A media query (@media) lets you apply different CSS based on the viewport condition. max-width means "if the screen width is less than or equal to this value". This is the main way to make a website responsive.

Responsive typography means setting different text sizes at each screen size. Text that's comfortable to read on desktop can be too big on a phone. Use several tiered media queries (mobile-first) to set the size gradually.

A responsive layout changes the arrangement of elements based on the screen size. A common pattern: 1 column on a phone (easy to scroll), 2 columns on a tablet, and 3+ columns on a desktop. Use grid-template-columns inside a media query.

An image with a fixed size (px) can overflow its container on a small screen. The basic responsive image technique: max-width: 100% so it doesn't overflow, and height: auto so the aspect ratio is preserved.

Time to build a complete page layout. A common pattern: mobile-first (column/stacked) then change to a side-by-side layout (row) on a large screen. The header and footer stay full-width, the sidebar + main change their arrangement.

What the levels ask

  1. Set the width of .box to 50vw so it's always half the screen.
  2. Set the height of .hero to 100vh so it fills the screen height.
  3. Set the width of .sidebar to 30% and .main to 70%.
  4. Set the width of .container to min(90vw, 600px) so it's not too wide.
  5. Change the background color of .box to red (#ef4444) when the screen is below 768px.
  6. Set the font-size of .text to 24px when the screen is at least 768px.
  7. Hide .sidebar on small screens (below 768px) using display: none.
  8. Change the flex-direction of .layout to column on small screens (below 768px).
  9. Set the font-size of .title: 16px on phone, 24px on tablet (min-width: 768px), 32px on desktop (min-width: 1024px).
  10. Set the padding of .card: 10px on phone, 20px on tablet (min-width: 768px), 40px on desktop (min-width: 1024px).
  11. Set the font-size of .title using clamp(16px, 4vw, 32px).
  12. Set the gap of .grid: 8px on phone, 16px on tablet (min-width: 768px), 24px on desktop (min-width: 1024px).

And more, 24 levels in all.