html · level 3 · unit 3 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
The viewport tag tells phones to show the page at their own width.
Long ago, websites were built for wide computer screens. So phones still pretend to be about 980 pixels wide, unless told otherwise, and shrink the whole page until the words are too small to read.
<meta name="viewport" content="width=device-width, initial-scale=1"> fixes that. It tells the browser to make the viewport as wide as the , whether that is a phone, a tablet or a laptop, and to start at normal size.
Never add user-scalable=no or maximum-scale=1. They stop people from making the page bigger, and many people need to to read.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Wag and Walk</title>
</head>
<body>
<h1>Wag and Walk</h1>
<p>Dog walks that fit around your day.</p>
</body>
</html> Press show my page to see it here.
name says which fact a <meta> holds, and content holds the fact itself.
guess first
What does this viewport tag stop people doing?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>Bus times</title>
</head>
<body>
<h1>Bus times</h1>
</body>
your turn
Your turn. Make the page fit the phone.
Fill line 5 with the name and content of the viewport tag, so phones show this page at their own width.
Press show my page to see it here.
- the viewport matches the device's widthnot checked yet
- people can still zoomnot checked yet
fix it
Nobody can zoom in. Can you fix it?
Press show my page to see it here.
- the viewport tag allows zoomingnot checked yet
- there is no maximum scalenot checked yet
- The page fits the phone, but pinching does nothing. Which part of
contentis to blame? maximum-scale=1stops the page from ever growing bigger than its starting size.- Delete
, maximum-scale=1from line 5, then press run.
nailed it
your page fits every phone. :D
- Every page needs the viewport tag.
width=device-width, initial-scale=1matches the device.- Never stop people from zooming.
new words in your collection
- device
- zoom
This lesson isn’t saved. A free account remembers every lesson you finish.