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
Key principle:
Responsive design starts with a mobile-first mindset. Build for the smallest screen first, then enhance for larger screens using CSS media queries and modern functions like clamp().

Responsive navbar: Hamburger menu (CSS-only)

The checkbox hack is a clever CSS technique that creates a hamburger menu without any JavaScript. It uses a hidden checkbox input, a label styled as a button, and the ~ (sibling) selector to toggle visibility.

hamburger-nav.html CSS checkbox hack for mobile menu

How it works:

  1. The <input type="checkbox"> is invisible to users but its :checked state is readable by CSS.
  2. Clicking the label toggles the checkbox (no JavaScript!).
  3. The ~ (adjacent sibling) selector targets the .nav-menu when the checkbox is checked.
  4. We animate the hamburger lines to form an X when open, creating a polished UX.
Pro tip:
The :checked selector only affects elements that come after the checkbox in the HTML. If your label/menu are before the checkbox, the CSS won't work. Order matters!

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!

โœ๏ธ Try It Yourself โ€” Hamburger Menu
Preview

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!

clamp-typography.css Fluid font sizing with clamp()

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.
Better than breakpoints:
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!

โœ๏ธ Try It Yourself โ€” Responsive Cards
Preview

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

responsive-table.html Scrollable table on mobile

Pattern 2: Card layout for mobile

For very narrow screens, convert the table to a card-based layout where each row becomes a card:

table-to-cards.css Table as cards on mobile

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:

responsive-images.html Picture element for different screens

Using srcset for different DPI

Serve multiple resolutions to handle high-DPI screens (like iPhone's Retina):

srcset-dpi.html Srcset for device pixel ratios
Challenge: Build a Responsive Page

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 ~ sibling selector.
  • 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: block and data- attributes.
  • Responsive images: Use <picture> for different image files per breakpoint, or srcset for different DPI versions.

Test your knowledge

Question 1 of 5
What CSS function creates fluid typography that scales smoothly?
Question 2 of 5
How does the hamburger menu checkbox hack work?
Question 3 of 5
What does clamp(1rem, 2.5vw, 2rem) mean?
Question 4 of 5
How do you make a table scrollable horizontally on mobile?
Question 5 of 5
Which HTML element provides different images for different screen sizes?
0
/5
Great work! You understand responsive patterns.
Africa & India's Best AI Academy
๐Ÿค– AI-first ๐ŸŽ“ Placement Assistance

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 โ†’