CSS and Metadata: The HTML Viewport Tag


Creating a responsive and mobile friendly site happens mostly in the CSS stylesheets with media queries and responsive rules, however there is one absolutely vital line of HTML that must be included in your site’s header file if you want your pages to be responsive, and that’s the meta viewport tag.

Join us in our newest publication:

The viewport is the area of a page that’s visible to the viewer. As you probably know, the viewport on a laptop or a desktop monitor is significantly larger than that of a mobile phone or tablet, which is the whole reason that responsive design is necessary at all. The goal of responsive and mobile friendly designs is to make sure that a page looks just as good on a mobile device as it does on a desktop. So to create a truly responsive design, we need to be able to control the viewport. That’s where the meta viewport tag comes in:

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

That one simple line above will make it so that the width of your user’s device = the width of your page. The one line of HTML combined with your media queries will allow for your pages to become completely mobile friendly and responsive.

To see the viewport meta tag in action, take a look at the two images below. The first is a screenshot of what CSS Reset looks like on a mobile device without the viewport tag, and the second is screenshot of how it looks with the viewport tag. The difference is pretty clear…so make sure you don’t forget to add the viewport tag when you’re creating your next responsive page.

Screen Shot 2016-11-13 at 9.08.17 AM

Screen Shot 2016-11-13 at 9.08.38 AM

Share and Enjoy !

0 0