{"id":165586,"date":"2014-03-13T12:37:13","date_gmt":"2014-03-13T19:37:13","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=165586"},"modified":"2014-03-17T07:15:57","modified_gmt":"2014-03-17T14:15:57","slug":"responsive-meta-tag","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/snippets\/html\/responsive-meta-tag\/","title":{"rendered":"Responsive Meta Tag"},"content":{"rendered":"

I tend to use this:<\/p>\n

<meta name=\"viewport\" content=\"width=device-width\"><\/code><\/pre>\n

Although I see this is recommended a lot: <\/p>\n

<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><\/code><\/pre>\n

This means that the browser will (probably) render the width of the page at the width of its own screen. So if that screen is 320px wide, the browser window will be 320px wide, rather than way zoomed out and showing 960px (or whatever that device does by default, in lieu of a responsive meta tag).<\/p>\n

Note:<\/strong> don’t<\/a> use a responsive meta tag if your website isn’t specifically designed to be responsive and work well at that size, as it will make the experience worse.<\/p>\n

There are more attributes<\/a> this tag supports:<\/p>\n\n\n\n\n\n\n\n\n\n\n\n
Property<\/th>\nDescription<\/th>\n<\/tr>\n
width<\/td>\nThe width of the virtual viewport of the device. <\/td>\n<\/tr>\n
device-width<\/td>\nThe physical width of the device’s screen.<\/td>\n<\/tr>\n
height<\/td>\nThe height of the “virtual viewport<\/em>” of the device.<\/td>\n<\/tr>\n
device-height<\/td>\nThe physical height of the device’s screen.<\/td>\n<\/tr>\n
initial-scale<\/td>\nThe initial zoom when visiting the page. 1.0 does not zoom.<\/td>\n<\/tr>\n
minimum-scale<\/td>\nThe minimum amount the visitor can zoom on the page. 1.0 does not zoom.<\/td>\n<\/tr>\n
maximum-scale<\/td>\nThe maximum amount the visitor can zoom on the page. 1.0 does not zoom.<\/td>\n<\/tr>\n
user-scalable<\/td>\nAllows the device to zoom in and out. Values are yes or no.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

It’s generally recommended that you don’t prevent scaling, as that’s annoying and potentially an accessibility problem.<\/p>\n

You’ll probably want this<\/a> in your CSS as well:<\/p>\n

@-ms-viewport{\r\n  width: device-width;\r\n}<\/code><\/pre>\n

Good to know: changing the value of this meta tag with JavaScript does work, the page will react to the new value. Either out the entire tag and replace, or change the content<\/code> property. Not a super common need, but it can come up.<\/p>\n","protected":false},"excerpt":{"rendered":"

I tend to use this: <meta name=”viewport” content=”width=device-width”> Although I see this is recommended a lot: <meta name=”viewport” content=”width=device-width, initial-scale=1″> This means that the browser will (probably) render the width of the page at the width of its own screen. So if that screen is 320px wide, the browser window will be 320px wide, rather […]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":3231,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"page-snippet.php","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":""},"tags":[],"acf":[],"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/165586"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=165586"}],"version-history":[{"count":6,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/165586\/revisions"}],"predecessor-version":[{"id":263415,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/165586\/revisions\/263415"}],"up":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3231"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=165586"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=165586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}