Responsive Web Design

Media queries, mobile-first design.

Introduction

Responsive Web Design (RWD) ensures your website looks good on all devices, from mobile phones to large desktops. It is no longer optional; it is mandatory for user experience and SEO.

In this chapter, you will learn:

  • Core concepts: Flexible layouts, images, and media queries
  • Mobile-first design strategy
  • Using common breakpoints
  • Responsive layouts with Flexbox and Grid

Core Concepts

1. Flexible Layouts

Avoid fixed widths (px). Use relative units (%, vw, rem).

/* Bad */
.container { width: 1200px; }

/* Good */
.container { width: 100%; max-width: 1200px; }
2. Flexible Images

Prevent images from overflowing their container.

img {
  max-width: 100%;
  height: auto;
}
3. Media Queries

Apply styles based on screen width.

@media (max-width: 768px) {
  body { background-color: #f5f5f5; }
}

Common Breakpoints

DeviceWidth
Mobile≤ 576px
Tablets≤ 768px
Laptops≤ 1200px
Large Screens> 1200px

Mobile-First Design

Start styling for mobile, then add styles for larger screens using min-width.

/* Base styles (Mobile) */
.card { padding: 15px; }

/* Tablet and up */
@media (min-width: 768px) {
  .card { padding: 30px; }
}

Responsive Layouts

Using Flexbox
.container {
  display: flex;
  flex-wrap: wrap;
}
.item { width: 100%; }

@media (min-width: 768px) {
  .item { width: 50%; }
}
Responsive Navigation
.nav { display: none; } /* Hidden/Hamburger on mobile */
@media (min-width: 768px) {
  .nav { display: flex; } /* Visible on desktop */
}

Common Beginner Mistakes & Best Practices

Common Mistakes
  • Designing only for desktop
  • Using fixed widths (px) everywhere
  • Using too many breakpoints
  • Ignoring touch targets on mobile
Best Practices
  • Adopt Mobile-First approach
  • Test on real devices
  • Use clamp() for fluid typography
  • Ensure inputs are at least 16px (prevent zoom)

Chapter Summary

In this chapter, you learned:

  • The importance of Responsive Web Design (RWD).
  • How to use fluid layouts, flexible images, and media queries.
  • Best practices for mobile-first design and responsive typography.
  • How to handle navigation and layouts on different screens.

You now understand how to build websites that work perfectly on all devices.