What are responsive patterns?
Responsive patterns are reusable CSS techniques that make websites adapt beautifully to any screen size โ from a 320px phone to a 4K monitor. They're the building blocks of modern web design.
In this lesson, you'll learn the four essential patterns used in production websites:
- Responsive navigation โ Hamburger menus that collapse on mobile (no JavaScript needed!)
- Fluid typography โ Text that scales smoothly with viewport size
- Responsive grids โ Cards that reflow from 1 column on mobile to 3+ on desktop
- Responsive tables & images โ Content that adapts when horizontal space is tight
clamp().
Try it yourself: Build a hamburger menu
Click Run to see the hamburger menu in action. Try resizing the preview or clicking the hamburger button. Notice: no JavaScript, just CSS!
Fluid typography with clamp()
The clamp() CSS function creates text that scales smoothly between a minimum and maximum size. No need for multiple media queries โ one line of CSS handles all breakpoints!
How clamp() works:
clamp(min, preferred, max)has three values.- min: The smallest the value can be (e.g., 24px). On tiny screens, text won't shrink below this.
- preferred: A flexible value that scales with viewport (e.g., 5vw). This is what you'll see on most devices.
- max: The largest the value can be (e.g., 48px). On huge screens, text won't grow beyond this.
clamp() eliminates jarring jumps at media query breakpoints. Text scales smoothly across all screen sizes for a more polished feel.
Try it yourself: Responsive cards with clamp()
This editor shows cards that use clamp() for smooth typography scaling AND CSS Grid to reflow from 1โ2โ3 columns. Resize the preview to see it in action!
Responsive tables
Tables are tricky on mobile because they're often too wide. Here are two proven patterns: horizontal scrolling and card layout.
Pattern 1: Horizontal scroll wrapper
Pattern 2: Card layout for mobile
For very narrow screens, convert the table to a card-based layout where each row becomes a card:
Responsive images with picture and srcset
Modern responsive image techniques let you serve different images to different devices, saving bandwidth on mobile and using sharp images on high-DPI screens.
Using the picture element
The <picture> element lets you choose images based on media queries:
Using srcset for different DPI
Serve multiple resolutions to handle high-DPI screens (like iPhone's Retina):
Task: Create a responsive page with:
- A hamburger menu that collapses on mobile (checkbox hack)
- A hero section with fluid typography using clamp()
- A 1โ2โ3 column responsive card grid
- A mobile-responsive table with horizontal scroll
Use the Try It Yourself editors above as templates. Combine the hamburger menu from Editor 1 and the card grid from Editor 2!
Hint: Build mobile-first. Start with 1-column layout and single-size text, then add media queries for wider screens. Use clamp() for typography instead of multiple breakpoints. The checkbox hack checkbox must come before the label and nav in your HTML.
Key takeaways
- Hamburger menus don't need JavaScript. Use the CSS checkbox hack: hidden
<input type="checkbox">+ label +:checked ~ siblingselector. - clamp() creates fluid typography that scales smoothly without media queries:
font-size: clamp(min, preferred, max). - Responsive grids use CSS Grid with media queries to reflow from 1โ2โ3 columns based on viewport width.
- Tables on mobile: Wrap in a scrollable container OR convert to card layout with
display: blockanddata-attributes. - Responsive images: Use
<picture>for different image files per breakpoint, orsrcsetfor different DPI versions.
Test your knowledge
You just built responsive patterns.
Imagine building full-stack apps next.
Join the Best AI Programs โ three 5-month courses, fully online, with placement assistance. Week 1 is free.
Explore our AI-era courses โ