InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search
  • Home
  • > Tutorials
  • > CSS cookbook

viewport and media queries for mobile browsers – quick introduction

By admin | Last updated on Mar 16, 2016

Html meta tag viewport should be set to appropriate value for responsive web sites. Viewport content values like width define how the site will render on mobile device.

Few possible viewport values

Here are some possible viewport values:

  1. Viewport which allows user resizing/scaling
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    You typically will want to use this value.

  2. Viewport which does not allow user resizing/scaling
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scaling=no" />
  3. Viewport with width fixed which does not allow user resizing/scaling
    <meta name="viewport" content="width=300, initial-scale=1.0, user-scaling=no" />

Using css3 media queries for responsive design

In case you want to define css which applies to screen width < 480px, you can use the following css:

@media screen and (max-width: 480px) {
  /* desired css */
}

In case you want to define css which applies to screen width > 480px and width < 600px

@media screen and (min-width: 480px) and (max-width: 600px) {
  /* desired css */
}

Note that even though media queries are more relevant for mobile browsers, they also work for desktop browser when browser window is resized. This is pretty handy to test the css during development.

Few points to note

  1. fixed width of any html element takes precedence over viewport value. e.g. If viewport is 100 but a div tag itself has a width of 200px, the display will be 200px for the div.
  2. If viewport is not specified the default viewport width of mobile may be used. its best to define the viewport for sites which can be accessed on mobile.
  3. Viewport has not effect on desktop browsers like Google Chrome, Firefox. It is only used for mobile.
  4. Typically responsive design use width for responsiveness. Use of height does not seem to be required.
  5. You may want to visit css3 w3 media queries spec for more info on media queries. Also note that IE8 does not support css3.

Suggested posts:

  1. How to view your WiFi password on Mac
  2. CSS – drop cap effect
  3. Git – how to undo last commit
  4. How to disable dropbox photo auto upload on mobile and desktop
  5. Rotate an element using css transform
  6. WordPress – get posts/pages with missing meta key
  7. jQuery – difference between html() and text()
  8. Run Internet Explorer (IE) on Mac using VirtualBox and ievms script
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged CSS, CSS cookbook, HTML, Tutorials, Web Development
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress