Media Queries: How to target desktop, tablet, and mobile?
IMO these are the best breakpoints:
@media (min-width:320px) { /* smartphones, portrait iPhone, portrait 480x320 phones (Android) */ }
@media (min-width:480px) { /* smartphones, Android phones, landscape iPhone */ }
@media (min-width:600px) { /* portrait tablets, portrait iPad, e-readers (Nook/Kindle), landscape 800x480 phones (Android) */ }
@media (min-width:801px) { /* tablet, landscape iPad, lo-res laptops ands desktops */ }
@media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ }
@media (min-width:1281px) { /* hi-res laptops and desktops */ }
Edit: Refined to work better with 960 grids:
@media (min-width:320px) { /* smartphones, iPhone, portrait 480x320 phones */ }
@media (min-width:481px) { /* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */ }
@media (min-width:641px) { /* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */ }
@media (min-width:961px) { /* tablet, landscape iPad, lo-res laptops ands desktops */ }
@media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ }
@media (min-width:1281px) { /* hi-res laptops and desktops */ }
In practice, many designers convert pixels to em
s, largely because em
s afford better zooming. At standard zoom 1em === 16px
, multiply pixels by 1em/16px
to get em
s. For example, 320px === 20em
.
In response to the comment, min-width
is standard in "mobile-first" design, wherein you start by designing for your smallest screens, and then add ever-increasing media queries, working your way onto larger and larger screens.
Regardless of whether you prefer min-
, max-
, or combinations thereof, be cognizant of the order of your rules, keeping in mind that if multiple rules match the same element, the later rules will override the earlier rules.
What are good resolution values to use with media queries?
See this article for a template '320 and Up' - by Andy Clarke, it's used by many developers and designers: http://www.stuffandnonsense.co.uk/blog/about/this_is_the_new_320_and_up
If you scroll down to the media queries section you'll see they use five CSS3 Media Query increments (480, 600, 768, 992 and 1382px). Typically I stick to just 4 (480, 600, 768, 1024).
To explain the ranges:
min-width: 480px
: Will target mobile devices in landscape mode and up
min-width: 600px
: Targets tablets in portrait mode and up
min-width: 768px
: Targets tablets in landscape mode and up
min-width: 1024px
: Targets the desktop view
And typically I will have my mobile portrait view CSS at the very beginning (hence the term "320 and up").
Related Topics
What Are Most Useful Media="Print" Specific, Cross Browser Compatible CSS Properties
Input[Type=Number] Placeholder Color in Ff29+
Add HTML Tag Inside CSS Content Property
CSS Background-Image Path Issues
Why Border of <Tr> Not Showing in Ie
CSS Property Box-Reflect Compatibility
Bootstrap 4 Row Height Set by Specific Col - Not Highest One
How to Create Pure CSS 3-Dimensional Spheres
Vertically Rotate Text Inside an HTML Table Header Cell
How to Remove Whitespace That Appears After Relative Positioning an Element with CSS
Google Custom Search (Csev2) Help on Styling
CSS Selectors - How to Select 'For' in CSS
Why Does My Font Look Much Better in IE9
How to Make Ie Support Min-Width/Max-Width CSS Properties
Svg Spritesheet Targeting with CSS
Why Can't I Seem to Use Background-Clip
Putting -Moz-Available and -Webkit-Fill-Available in One Width (CSS Property)