Skip to content

Responsive Web Design: viewport meta tag, media queries, mobile first and clamp()

NeedMyTools Academy

Sign in free to read the full lesson

Sign in or create a free account

Free forever. No card, no paywall.

Most visitors to sites in the Gulf arrive on a phone, often with the screen in one hand while waiting in a queue or on a bus. A page that looks perfect on a laptop but needs pinching and sideways scrolling on a phone loses those people in seconds. Responsive design means one page, one set of HTML, that adapts its layout to whatever screen it is shown on. You already have most of the tools: Flexbox and Grid adapt by themselves. This lesson adds the missing pieces: the viewport tag, flexible media, media queries and fluid sizes.

Quick answer

Add <meta name="viewport" content="width=device-width, initial-scale=1"> to the head so phones use their real width. Make images flexible with max-width: 100% and height: auto, avoid fixed widths, and size text in rem. Write the phone layout first, then add @media (min-width: 40rem) { ... } blocks for wider screens, choosing breakpoints where the content starts to look wrong, not by device names. clamp() scales text smoothly between a minimum and a maximum.

25 min read and practice · Content checked on 29 October 2026

In this lesson you will

  • Add the viewport meta tag and explain what breaks without it
  • Make images and boxes flexible so nothing scrolls sideways at 320 pixels
  • Write mobile-first media queries and pick breakpoints from the content
  • Scale headings with clamp() and respect user preferences such as reduced motion

The viewport meta tag

Phone browsers were built at a time when most sites were designed only for desktops. To show those sites at all, a phone pretends its screen is about 980 pixels wide and then zooms the whole page out, so text becomes tiny. Your media queries never fire, because the browser thinks it is a wide screen. One line in the head switches this off: <meta name="viewport" content="width=device-width, initial-scale=1"> tells the browser to use the device’s real width at normal zoom.

Put it on every page, right after the charset line. Do not add user-scalable=no or maximum-scale=1 to stop people zooming: people with low vision rely on pinch zoom, and blocking it can fail WCAG success criterion 1.4.4, Resize Text. The sizes media queries talk about are CSS pixels, not the physical pixels of the screen, so a phone with a very sharp display still reports a width of around 360 to 430 CSS pixels.

Sign in free to read the full lesson

You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.

Unlocks after sign-in:

  • 3 more sections with live code examples
  • Common mistakes to avoid
  • Hands-on coding exercise with automatic checks
  • Practice quiz and the graded lesson test
Sign in or create a free account

Free forever. No card, no paywall.

Questions people ask

What is responsive web design?

It is building one page that adapts its layout to the screen it is viewed on, from a small phone to a wide monitor, using flexible layouts, flexible images and media queries. It replaced the old approach of a separate mobile site at an address such as m.example.com.

What breakpoints should I use for mobile, tablet and desktop?

There is no official list. Many sites end up with breakpoints near 40rem (640px) and 64rem (1024px), but the right ones are where your layout needs them. Start with the phone layout, widen the window, and add a query only where something breaks.

Should I use min-width or max-width media queries?

Prefer min-width with a mobile-first stylesheet: the base CSS is the simple phone layout and each query adds to it. max-width queries are fine for small fixes, but a stylesheet built mostly on them tends to undo desktop styles for phones, which means more code.

Is it OK to stop users zooming with the viewport tag?

No. user-scalable=no and maximum-scale=1 block pinch zoom, which people with low vision depend on, and accessibility checkers based on WCAG report it as a failure. Fix the layout so it does not need blocking instead.

What is the difference between media queries and container queries?

Media queries test the whole browser window or device, such as its width or dark mode setting. Container queries test the size of a parent element, so one component can change its own layout wherever it is placed. Both work in all current major browsers.

Sources

Facts in this lesson were checked against these official pages on 29 October 2026.

Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.