Responsive design with media queries

Beginner  Nov 3, 2026

Make one page work on phones, tablets and desktops.

Responsive design with media queries
The steps of this tutorial at a glance.
The steps of this tutorial at a glance.

Step 1: the viewport tag

Put this in the <head>. Without it phones pretend to be wide desktops:

<meta name="viewport" content="width=device-width, initial-scale=1">
How the code in this section fits into the page.
How the code in this section fits into the page.

Step 2: write for phones first

.cards { display: grid; gap: 16px; }          /* one column by default */

@media (min-width: 700px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1000px) {
  .cards { grid-template-columns: repeat(3, 1fr); }
}

Mobile-first (min-width) means small screens load the simple styles and larger screens add more.

Pick breakpoints from your content

Common starting points are 600px, 900px and 1200px. If the layout looks bad at some width, add a breakpoint there. Do not chase specific devices.

Pick breakpoints from your content
Pick breakpoints from your content

Other useful queries

@media (prefers-color-scheme: dark) { body { background: #111; color: #eee; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
@media print { nav { display: none; } }

Test

Drag the browser window narrower, then use DevTools device mode to check real phone sizes. Also check with your thumb: are buttons big enough to tap?

More tutorials