Web development

Set a useful viewport for responsive pages

Include a viewport meta tag so mobile browsers lay out a responsive page using the device width. Pair it with flexible CSS rather than fixed desktop-width containers.

Worked example

HTML example · save as example.html and open in a browser

<!doctype html>
<html lang="en"><head>
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <title>Responsive example</title>
  <style>main{max-width:60rem;margin:auto;padding:1rem}img{max-width:100%;height:auto}</style>
</head><body><main><h1>A flexible page</h1><p>Content can wrap to the available width.</p></main></body></html>

How it works

Device width makes CSS pixels align with the mobile layout viewport rather than a wider virtual desktop canvas. The maximum width keeps long desktop lines readable, while padding and natural wrapping preserve space on small screens.

Limits and mistakes

The tag alone cannot fix a 1200-pixel child element or a long unbreakable string. Avoid disabling pinch zoom through maximum-scale or user-scalable settings. Users may need magnification even on a responsive page.

Check the result

Inspect the page at a narrow width and zoom it. Confirm text wraps, content is reachable, and there is no unnecessary horizontal page scroll.

Sources

Reference documentation for the behavior used in this guide: