InfoHeap
Tech tutorials, tips, tools and more
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 desktop site from android mobile
  2. Xml sitemap – quick introduction
  3. haxe openfl on mac – quick start guide for mobile development
  4. Cross browser site testing – what browsers to cover
  5. How to bypass cross site scripting (XSS) protection by browsers
  6. Mysql – get total queries since beginning
  7. jQuery – check if element is visible in viewport ofter scroll
  8. node-sass quick start tutorial on Linux and Mac
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

Follow InfoHeap

facebook
twitter
googleplus
  • Browse site
  • Article Topics
  • Article archives
  • Recent Articles
  • Contact Us
  • Omoney
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | 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

Copyright © 2023 InfoHeap.

Powered by WordPress