DevAcademy
LearnCSSResponsive Design
AdvancedCSS

Responsive Design

Learn how to build layouts that adapt to different screen sizes using media queries and a mobile-first approach.

Reading Time

20 min

Lesson

Lesson 22 of 30

What is Responsive Design?

Responsive design means building pages that adapt their layout to fit any screen size — from a small phone to a large desktop monitor — using flexible layouts and media queries.

Media Queries

A media query applies a block of CSS only when certain conditions are met, most commonly a minimum or maximum viewport width.

A Basic Media Query

<style>
  .box {
    background: steelblue;
    color: white;
    padding: 20px;
    font-size: 16px;
  }

  @media (max-width: 480px) {
    .box {
      background: crimson;
      font-size: 14px;
    }
  }
</style>

<div class="box">Resize the preview panel to see this change color below 480px.</div>
Output

Mobile-First Design

Mobile-first means writing your base CSS for small screens first, then using min-width media queries to add complexity as the screen grows — generally simpler than starting from desktop and overriding down.

Mobile-First Layout

<style>
  .layout {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .layout div {
    background: #eef4fb;
    padding: 16px;
  }

  @media (min-width: 600px) {
    .layout {
      flex-direction: row;
    }
  }
</style>

<div class="layout">
  <div>Panel A</div>
  <div>Panel B</div>
</div>
Output

Common Breakpoints (as a starting point)

RangeTypical Device
< 600pxMobile phones
600px – 900pxTablets
900px – 1200pxSmall laptops
> 1200pxDesktops and large screens

Fluid Layouts Reduce the Need for Breakpoints

Using Flexbox, Grid, percentages, and the fr unit often lets a layout adapt smoothly without any media queries at all — reach for breakpoints when the layout needs a structural change, not just resizing.

Don’t Forget the Viewport Meta Tag

Media queries only behave correctly on mobile if the HTML document includes <meta name="viewport" content="width=device-width, initial-scale=1.0" /> in its head — otherwise mobile browsers render at a zoomed-out desktop width.

Best Practice

Base your breakpoints on where your own content starts to look cramped or awkward, rather than copying exact device widths — devices and screen sizes change constantly, but your content’s natural breakpoints don’t.

Interview Questions

Quick Quiz

1. What does a media query with (max-width: 480px) do?

2. What does "mobile-first" mean?

3. Why is the viewport meta tag important for responsive design?