Skip to content
BENIBIX Learn

Viewport Meta Tag

Development🌐 Web DevelopmentBrowser Code

Also known as Meta Viewport, width=device-width, Viewport Meta Element

One line of HTML that makes a page fit the width of a phone screen.

Think of it like

It is like telling a tailor your real size. Then the shirt fits you, not a giant.

Example

Jack's new site looks tiny on his phone, and his mobile styles never kick in. He adds the viewport tag, and the page fits.

Why it matters

It is the first step of any page that works on phones. Without it, responsive design does not work at all.

Definition

The viewport meta tag is one line of HTML that tells a phone how wide to lay out the page. It goes in the head of the page. Without it, many phones pretend the screen is as wide as a desktop and shrink the page down. With width=device-width, the page is laid out at the phone's real width. Media queries for small screens only work once this line is there.

Example code

html
<meta name="viewport" content="width=device-width, initial-scale=1">
The line most pages use. It sets the page width to the screen width, at normal zoom.
Without the tag, the page is shrunk. With it, the page fits the phone.

Common mistake

Adding user-scalable=no to stop zoom. People who need bigger text can then not zoom in.

Key takeaways

  1. 1
    One line. It goes in the head of the page.
  2. 2
    Real width. The page is laid out at the screen width.
  3. 3
    Let people zoom. Never turn zoom off.

Compare

Learn it properly