Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is the meta viewport tag used, and what does it do?

  1. What browsers support this meta tag?
  2. How do i use it?
  3. Does this mean it will solve all my mobile resizing problems?

If anyone could answer this it would be a great help to newbies learning

<meta="viewport"> 
like image 299
Kyle Yeo Avatar asked Jun 05 '12 06:06

Kyle Yeo


People also ask

What is the use of viewport meta tag?

Setting the viewport meta tag lets you control the width and scaling of the viewport so that it's sized correctly on all devices.

What is viewport and why is it needed?

A viewport is a term for the visible area of a webpage on a display device. It is used in both code and analog design as a way to refer to the display screen and how layout fits into that screen.

Where do I put meta viewport tag?

Generally, meta elements (including viewport) should be placed in the document's <head> . CSS rules should either be added to a CSS stylesheet and referenced with a <link> element or, if you're not using stylesheets for some reason, in a <style> element (also in the document's <head> ).

Why is the viewport meta tag used when a web page is to be made responsive?

The HTML Viewport meta tag is used for creating responsive website. So that web page can adjust its width according to viewport.


2 Answers

  1. The viewport browser support is a little bit across the board. I'll point you to the Quirksmode page for viewport browser support for the full details.
  2. You use the viewport meta tag like any other meta tag. Put the code block straight up in the <head>.
  3. Pretty much, but again, a little bit of a mouthful to say here. I'd advise reading some articles, reading the W3 mobile best practices for web design, or the current W3 draft specifications on the viewport attribute for the <meta> tag.

In short, adding this line to a website that should implement viewport scaling should fix most problems. (copied from WebDesignTuts+'s "Quick Tip: Don't Forget the Viewport Meta Tag" article)

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

P.S. Quirksmode also has a rather wonderful article describing the issue that's worth reading to understand why this might be helpful.

like image 129
Nightfirecat Avatar answered Sep 20 '22 14:09

Nightfirecat


Another article about meta viewport, its various properties, and how to use it in your designs is http://dev.opera.com/articles/view/an-introduction-to-meta-viewport-and-viewport/

There's also a slidedeck explaining things in detail and a Github repo to go with it.

Disclaimer: I'm the author of these resources.

like image 29
andreasbovens Avatar answered Sep 22 '22 14:09

andreasbovens