Why it matters
- On phones, when a page does not ask for the device's width, the browser lays it out at a width that suits a computer screen and then shrinks it. The text gets small, and visitors have to zoom and scroll sideways to read.
- In search, Google indexes the phone version of a page, so a page that does not suit phones gives searchers a poor experience.
- A fixed width, such as
width=1024, forces the page to be wider than most phone screens, so it scrolls sideways.
Example
<meta charset="utf-8" /> <title>لبان حوجري | متجر الواحة</title>
<meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>لبان حوجري | متجر الواحة</title>
How to fix
Add this tag inside <head>:
html
<meta name="viewport" content="width=device-width, initial-scale=1" />- If the tag has a fixed width such as
width=1024, replace it withwidth=device-width, and design the page to fit any width. - Most modern themes have this tag in the page header template, such as
header.phpin WordPress ortheme.liquidin Shopify.
How we detect
- We read the page's HTML as the server sends it, without running JavaScript.
- We read the first
<meta name="viewport">tag and split its properties as browsers do: on commas, semicolons and spaces, in any letter case. - The rule passes when it has
width=device-width, or sets no width but setsinitial-scale, since the browser then takes the device's width. It fails when the tag is missing, sets another width, or sets neither.