Course contentsShow
← Web Development
Lesson 83 of 2,9822. HTML FundamentalsFree lesson

Viewport Configuration for Responsive Design

Using the viewport meta tag to control mobile browser rendering and scaling.

What You'll Learn

You'll learn how to use the viewport meta tag to ensure your web pages display correctly on mobile devices and tablets.

The Mobile Rendering Problem

Without instructions, mobile browsers try to be "helpful" by pretending they have a desktop-sized screen (usually 980 pixels wide). They render your entire page at that width, then shrink it down to fit the phone screen. This makes everything tiny and hard to read—users have to pinch and zoom just to read text.

The viewport meta tag tells the browser: "Don't pretend you're a desktop. Use your actual screen width and display content at a readable size."

The Viewport Meta Tag

Place this line inside your <head> element:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

Let's break down what each part means:

  • name="viewport" — identifies this as a viewport instruction
  • width=device-width — sets the page width to match the device's actual screen width (not a fake 980px)
  • initial-scale=1.0 — sets the starting zoom level to 100% (one CSS pixel equals one device pixel)

Think of It Like a Window

Imagine the viewport as a window frame. Without configuration, mobile browsers create a huge window (desktop-sized), paint your page inside it, then shrink that whole window down to phone size. With the viewport tag, you're saying "make the window the same size as the phone screen from the start."

This single line is essential for responsive design—it's the foundation that allows your page to adapt naturally to different screen sizes.

Key Takeaway: The viewport meta tag with width=device-width, initial-scale=1.0 ensures mobile browsers render your page at the correct scale instead of shrinking a desktop view.