Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

HTML Tutorial

HTML HOME HTML Introduction HTML Editors HTML Basic HTML Elements HTML Attributes HTML Headings HTML Paragraphs HTML Styles HTML Formatting HTML Quotations HTML Comments HTML Colors HTML CSS HTML Links HTML Images HTML Favicon HTML Page Title HTML Tables HTML Lists HTML Block & Inline HTML Div HTML Classes HTML Id HTML Iframes HTML JavaScript HTML File Paths HTML Head HTML Layout HTML Responsive HTML Computercode HTML Semantics HTML Style Guide HTML Entities HTML Symbols HTML Emojis HTML Charsets HTML URL Encode HTML vs. XHTML

HTML Forms

HTML Forms HTML Form Attributes HTML Form Elements HTML Input Types HTML Input Attributes Input Form Attributes

HTML Graphics

HTML Canvas HTML SVG

HTML Media

HTML Media HTML Video HTML Audio HTML Plug-ins HTML YouTube

HTML APIs

HTML Geolocation HTML Drag/Drop HTML Web Storage HTML Web Workers HTML SSE

HTML Examples

HTML Examples HTML Editor HTML Quiz HTML Exercises HTML Website HTML Interview Prep HTML Bootcamp HTML Certificate HTML Summary HTML Accessibility

HTML References

HTML Tag List HTML Attributes HTML Global Attributes HTML Browser Support HTML Events HTML Colors HTML Canvas HTML Audio/Video HTML Doctypes HTML Character Sets HTML URL Encode HTML Lang Codes HTTP Messages HTTP Methods PX to EM Converter Keyboard Shortcuts

HTML Mobile


HTML Mobile plays well with Media Queries


HTML Screen Size

In 2004 a common screen resolution was 800x600 pixels. Typical web sites had a 760px fixed width.

In 2008 most computer screens had a 1024x768 resolution. Typical web sites had a 980px width.

Today, web browsers can run on everything from high-resolution screens (2560x1600) to small tablets and smart phones.


Viewport Media Tags

The viewport media tag is placed inside the <head> tag of a page:

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

The meta tag above, allows a web page to be scaled up to the device with, when it is opened for the first time.


Media Queries

Media queries is placed inside the CSS file:

@media screen and (min-width: 200px) and (max-width: 400px) {
    img { display: none; }
}

The media query above hides all images when screen with is between 200px and 400px.

The next chapter of this tutorial will demonstrate a responsive web page.


Media Queries

Media queries (@media) is the CSS solution to the screen size problem.

In a style sheet you can have different media queries like:

Example

@media screen {
  p {
    font-family : verdana, sans-serif;
    font-size   : 12px;
  }
}

@media print {
  p {
    font-family : garamond, serif;
    font-size : 10px;
  }
    img {
    display:none
  }
}

The example above declares that paragraphs should be displayed differently on a screen than on a printer.

Another font-family and font-size should be used. In addition, images should not be printed on a printer.


Mobile and Tablets

For different screen resolutions, CSS allows us to add min-width and max-width:

Example

/* For smart phones */
@media screen and (max-width: 600px) {
}

/* For tablets */
@media screen and (min-width: 600px) and (max-width: 900px) {
}

/* For desktop computers */
@media screen and (min-width: 900px) {
}

You can also use other parameters:

Example

/* Device dimensions */
@media screen and (max-device-height: 600px) {
}

/* Device orientation */
@media screen and (orientation: portrait) {
}

/* Device aspect ratio */
@media screen and (device-aspect-ratio: 16/9) {
}


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.