Lab 09: Responsive Design

Objective

Build websites that look great on every screen β€” from smartphones to 4K monitors β€” using mobile-first design, media queries, fluid typography, and responsive images.

Background

Over 60% of web traffic comes from mobile devices. Responsive design isn't optional β€” it's the baseline. CSS provides powerful tools: viewport meta tag, @media queries, clamp(), srcset, and CSS custom properties. This lab covers all of them.

Time

35 minutes

Prerequisites

  • Lab 07: CSS Flexbox

  • Lab 08: CSS Grid

Tools

docker run --rm -it -v /tmp:/workspace zchencow/innozverse-htmlcss:latest bash

Lab Instructions

Step 1: Viewport Meta Tag & Mobile-First

Write this file:

πŸ’‘ Mobile-first means writing min-width media queries, not max-width. Start with the simplest layout (mobile) and progressively add complexity for larger screens. This results in leaner CSS and forces content prioritization.

πŸ“Έ Verified Output:


Step 2: Media Queries & Breakpoints

Write this file:

πŸ’‘ Common breakpoints: 640px (small tablet), 768px (tablet), 1024px (laptop), 1280px (desktop), 1536px (large). You don't need to use all of them β€” use breakpoints where your content naturally breaks, not based on device sizes.

πŸ“Έ Verified Output:


Step 3: Fluid Typography with clamp()

Write this file:

πŸ’‘ clamp(min, preferred, max) eliminates most font-size media queries. clamp(1rem, 2.5vw, 1.5rem) means: never smaller than 1rem, scale with viewport width, never larger than 1.5rem. vw = 1% of viewport width β€” great for fluid scaling.

πŸ“Έ Verified Output:


Step 4: Responsive Images

Write this file:

πŸ’‘ srcset + sizes tells the browser about multiple image versions and hints about display size. The browser then picks the optimal one based on screen size AND pixel density. picture element lets you serve completely different image crops for different screens β€” "art direction."

πŸ“Έ Verified Output:


Step 5: Breakpoint System

Write this file:

πŸ’‘ Breakpoints are about content, not devices. Don't say "this is the iPhone breakpoint" β€” say "at this width, my content starts to break." Add a breakpoint when the layout looks wrong, not based on device specs. Fewer breakpoints = simpler CSS.

πŸ“Έ Verified Output:


Step 6: Responsive Navigation

Write this file:

πŸ’‘ The hamburger pattern: Mobile shows a toggle button; desktop shows links inline. display: none hides links on mobile, display: flex shows them on desktop. One JavaScript toggle class handles the mobile open/close state.

πŸ“Έ Verified Output:


Step 7: CSS Custom Properties for Responsive Theming

Write this file:

πŸ’‘ CSS variables in media queries β€” update the variable, everything using it updates automatically. This is the DRY (Don't Repeat Yourself) principle applied to responsive design. Define spacing/typography scales as variables, adjust them at breakpoints.

πŸ“Έ Verified Output:


Step 8: Capstone β€” Fully Responsive Landing Page

Write this file:

πŸ’‘ Capstone recap: This landing page applies every technique from this lab: viewport meta, mobile-first CSS, clamp() typography, CSS variables, responsive grid (auto-fit), and a responsive navigation. The --pad variable alone eliminates 6+ repeated media query blocks.

πŸ“Έ Verified Output:


Verification

Summary

Technique
CSS
Purpose

Viewport meta

<meta name="viewport">

Enable proper mobile scaling

Mobile-first

@media (min-width: ...)

Progressive enhancement

Fluid type

clamp(min, vw, max)

Smooth scaling without jumps

Responsive images

srcset, sizes, picture

Right image for right screen

Responsive grid

repeat(auto-fit, minmax())

No media queries needed

CSS variables

--var in @media

Centralized responsive values

Further Reading

Last updated