Skip to article content
FrontendXLesson 22 / 30

Viewport meta and mobile-first thinking

Build semantic, accessible and responsive interfaces from a blank page, and explain why each layout and styling decision works.

beginner · about 30 minutes · 2 exercises

  • Predict
  • Implement

What you will be able to do

#
  • Explain what the viewport meta tag does on mobile.
  • Write base styles for the smallest screen and enhance upward.

Overview

#

Without a viewport meta tag, mobile browsers render the page at a virtual width of about 980px and then zoom out, so text is tiny and media queries never match the device width. width=device-width tells the browser to use the real device width as the layout viewport.

snippet.html
<meta name="viewport" content="width=device-width, initial-scale=1" />

Do not disable zoom with user-scalable=no or maximum-scale=1. Pinch zoom is an accessibility feature, and disabling it fails WCAG. Users with low vision rely on it.

Mobile-first means the base styles target the smallest screen and media queries add complexity for larger screens. This produces simpler CSS because the common case is the default, and it matches how most traffic arrives.

snippet.css
/* base: single column */
.layout { display: grid; gap: 1rem; }

/* enhance from 48rem up */
@media (min-width: 48rem) {
  .layout { grid-template-columns: 220px 1fr; }
}

Prefer min-width media queries over max-width. A max-width query describes a device rather than a need, and mixing both directions creates gaps and overlaps at the boundaries. With min-width, each breakpoint means 'from here up', and the rules compose predictably. Choose breakpoints where the content actually breaks, not at specific device widths, because devices change and content does not.

Exercises

#

Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.

  1. Exercise 1Implement

    Write a mobile-first layout that is a single column by default and two columns from 48rem up.

    starter.css
    .layout { /* base */ }
    /* add the media query */

    Reveal the reference answer
    reference.css
    .layout {
      display: grid;
      gap: 1rem;
    }
    @media (min-width: 48rem) {
      .layout { grid-template-columns: 1fr 1fr; }
    }

    Authored expected output: One column below 48rem and two equal columns at and above 48rem.

    The base rule handles the small screen and the min-width query enhances upward.

  2. Exercise 2Predict

    What does content="width=device-width, initial-scale=1" do on a phone?

    Choose the best answer

Common misconceptions

#
  • user-scalable=no is a harmless way to prevent accidental zoom.
  • Breakpoints should match popular phone widths exactly.

Follow-up practice

#
  • html-css-23-media-container-queries

Related resources

#

Your progress

#

Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.

Verification: authored. Answers and outputs on this page are authored reference material, not executed results.

© 2026 FrontendX. All rights reserved.