Which devices/recommended sizes should I target with mediaqueries? - css

I am new to responsive web design, and got confused because there are various preferences about which media queries to use and which devices to target. Is there a standard? I'd like to target iPhone, iPads, and other popular devices.
I have found this on the web:
/* Smartphones (portrait and landscape) ----------- */
#media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
#media only screen and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
#media only screen and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {
/* Styles */
}
/* Desktops and laptops ----------- */
#media only screen and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
#media only screen and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 and high pixel ratio devices ----------- */
#media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
But I do not know if it is outdated. I do not know which rule targets iPhone 4, because I ran the iPhone simulator and the CSS didn't work (referring to last CSS rule).

My thought with media queries is that your goal should be to make a device-agnostic framework for your website. That means it needs to be both resolution and pixel density aware, given Apple's (and others) push into super high resolution screens.
2018 update: my approach now drops the screen and min-device-pixel-ratio media attributes and uses screen-size ranges. Because every device now registers as screen, and almost all of them are high resolution now - you really don't need those attributes. If you're on a super high traffic site maybe they still make sense though.
Here is how I lay out my breakpoints globally:
/* Below 380px is really just the iPhone SE at this point */
#media (min-width: 380px) and (max-width: 480px) {
/* Most phones fall in here - iPhone, Galaxy, Pixel, etc */
}
#media (min-width: 480px) and (max-width: 768px) {
/* Phablets and Tablets - iPad, Galaxy Note, Pixel Slate, Fire */
}
#media (min-width: 768px) and (max-width: 980px) {
/* Small desktop, large tablet - Macbooks, sub 12" ultrabooks */
}
#media (min-width: 980px) and (max-width: 1200px) {
/* Medium screen desktop (up to about 24") and laptops (13" laptops) */
}
#media (min-width: 1200px) and (max-width: 1600px) {
/* Large screen desktop (27"), laptops (15+") */
}
#media (min-width: 1600px) {
/* Very large screen, 4K desktop + small TVs */
}
2012 advice: I've seen on achieving that dual mandate comes from Chris Coyier's CSS-tricks.com:
http://css-tricks.com/snippets/css/retina-display-media-query/
The concept is to create the initial break points based on size and then have pixel-density media queries follow. This approach gives you three breakpoints, and each breakpoint has a pixel-density-aware option.
Here is Coyier's sample code (I simplified out the vendor-specific prefixes so you can grasp the concept):
#media only screen and (min-width: 320px) {
/* Small screen, non-retina */
}
#media only screen and (min-device-pixel-ratio: 2) and (min-width: 320px) {
/* Small screen, retina, stuff to override above media query */
}
#media only screen and (min-width: 700px) {
/* Medium screen, non-retina */
}
#media only screen and (min-device-pixel-ratio: 2) and (min-width: 700px) {
/* Medium screen, retina, stuff to override above media query */
}
#media only screen and (min-width: 1300px) {
/* Large screen, non-retina */
}
#media only screen and (min-device-pixel-ratio: 2) and (min-width: 1300px){
/* Large screen, retina, stuff to override above media query */
}
I really like this concept: you save bandwidth for older, likely bandwidth constrained devices while giving the new, high-res devices what they need. The only code you would have to put in the pixel-density media queries should be background-image stuff, so the higher-res imagery overrides its pixelated counterpart on older devices.
Realize that you are trying to hit a moving target my friend ;) This is an evolving concept, css-tricks.com, stackoverflow and other blogs seem to be the best way to keep up. Good luck.

The "breakpoints" in your layout are likely to become quickly outdated as new devices with different viewport ratios come on the market. Perhaps rather than target specific devices, I prefer the approach of having breakpoints in your design where you want it to break, rather than bending your design to specific devices.
This article: Device-Agnostic Approach To Responsive Web Design explains it better than I could ever do.
Alternatively, you could refer to some of the most popular frameworks like 320 and Up or Twitter Bootstrap - they are updated very often and should provide you with a good starting point with media query breakpoints.

Related

Bootstrap media breakpoints

There are bootstrap 3 media breakpoints
/*========== Mobile First Method ==========*/
/* Custom, iPhone Retina */
#media only screen and (min-width : 320px) {
}
/* Extra Small Devices, Phones */
#media only screen and (min-width : 480px) {
}
/* Small Devices, Tablets */
#media only screen and (min-width : 768px) {
}
/* Medium Devices, Desktops */
#media only screen and (min-width : 992px) {
}
/* Large Devices, Wide Screens */
#media only screen and (min-width : 1200px) {
}
/*========== Non-Mobile First Method ==========*/
/* Large Devices, Wide Screens */
#media only screen and (max-width : 1200px) {
}
/* Medium Devices, Desktops */
#media only screen and (max-width : 992px) {
}
/* Small Devices, Tablets */
#media only screen and (max-width : 768px) {
}
/* Extra Small Devices, Phones */
#media only screen and (max-width : 480px) {
}
/* Custom, iPhone Retina */
#media only screen and (max-width : 320px) {
}
I just dont understand why in mobile first min-width and max-width in non-mobile described as equal. I mean for example min-width for tablets = 768px, so it means all widths > 768, and in max-width 768 for tablets too, but it means < 768px, it looks like range for tablets in mobile-first = 768-991px and in non-mobile 481-768
Bootstrap and in general all media queries usually define width breakpoints with ranges. In this case, in the css you showed, breakpoints with the same header comment are synonyms.
You can define better with the two options like this (for example):
/* Extra Small Devices, Phones */
#media only screen and (max-width: 480px) and (min-width: 321px) { }
You also can use another (and the posibility to concatenate) selectors to specify the screen position or other parameters. Here are some of this:
height
orientation
color-index
monochrome
resolution
scan
grid

Responsive design with media query : screen size?

I'm working on responsive designed web site using media queries. But i do not know how to take a good width set.
As you can see on this table, there is a lot of different resolution even for a single type of device. And as resolution is coming bigger and bigger on mobile device, it is hard to know what design to apply for a specific resolution.
For now, I'm using this :
Mobile First
#media screen and (min-width:720px) => Phablet
#media screen and (min-width:768px) => Tablet
#media screen and (min-width:1024px) => Desktop
Thank you for any advice or recomendations !
Responsive Web design (RWD) is a Web design approach aimed at crafting sites to provide an optimal viewing experience
When you design your responsive website you should consider the size of the screen and not the device type. The media queries helps you do that.
If you want to style your site per device, you can use the user agent value, but this is not recommended since you'll have to work hard to maintain your code for new devices, new browsers, browsers versions etc while when using the screen size, all of this does not matter.
You can see some standard resolutions in this link.
BUT, in my opinion, you should first design your website layout, and only then adjust it with media queries to fit possible screen sizes.
Why? As I said before, the screen resolutions variety is big and if you'll design a mobile version that is targeted to 320px your site won't be optimized to 350px screens or 400px screens.
TIPS
When designing a responsive page, open it in your desktop browser and change the width of the browser to see how the width of the screen affects your layout and style.
Use percentage instead of pixels, it will make your work easier.
Example
I have a table with 5 columns. The data looks good when the screen size is bigger than 600px so I add a breakpoint at 600px and hides 1 less important column when the screen size is smaller. Devices with big screens such as desktops and tablets will display all the data, while mobile phones with small screens will display part of the data.
State of mind
Not directly related to the question but important aspect in responsive design.
Responsive design also relate to the fact that the user have a different state of mind when using a mobile phone or a desktop. For example, when you open your bank's site in the evening and check your stocks you want as much data on the screen. When you open the same page in the your lunch break your probably want to see few important details and not all the graphs of last year.
Here is media queries for common device breakpoints.
/* Smartphones (portrait and landscape) ----------- */
#media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
#media only screen and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
#media only screen and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {
/* Styles */
}
/**********
iPad 3
**********/
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}
/* Desktops and laptops ----------- */
#media only screen and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
#media only screen and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
#media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}
#media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}
The screen widths Bootstrap v3.x uses are as follows:
Extra small devices Phones (<768px) / .col-xs-
Small devices Tablets (≥768px) / .col-sm-
Medium devices Desktops (≥992px) / .col-md-
Large devices Desktops (≥1200px) / .col-lg-
So, these are good to use and work well in practice.
Take a look at this...
http://getbootstrap.com/
For big websites I use Bootstrap and sometimes (for simple websites) I create all the style with some #mediaqueries. It's very simple, just think all the code in percentage.
.container {
max-width: 1200px;
width: 100%;
margin: 0 auto;
}
Inside the container, your structure must have widths in percentage like this...
.col-1 {
width: 40%;
float: left;
}
.col-2 {
width: 60%;
float: left;
}
#media screen and (max-width: 320px) {
.col-1, .col-2 { width: 100%; }
}
In some simple interfaces, if you start to develop the project in this way, you will have great chances to have a fully responsive site using break points only to adjust the flow of objects.
i will provide mine because #muni s solution was a bit overkill for me
note: if you want to add custom definitions for several resolutions together, say something like this:
//mobile generally
#media screen and (max-width: 1199) {
.irns-desktop{
display: none;
}
.irns-mobile{
display: initial;
}
}
Be sure to add those definitions on top of the accurate definitions, so it cascades correctly (e.g. 'smartphone portrait' must win versus 'mobile generally')
//here all definitions to apply globally
//desktop
#media only screen
and (min-width : 1200) {
}
//tablet landscape
#media screen and (min-width: 1024px) and (max-width: 1600px) {
} // end media query
//tablet portrait
#media screen and (min-width: 768px) and (max-width: 1023px) {
}//end media definition
//smartphone landscape
#media screen and (min-width: 480px) and (max-width: 767px) {
}//end media query
//smartphone portrait
#media screen /*and (min-width: 320px)*/
and (max-width: 479px) {
}
//end media query

Common CSS Media Queries Break Points [duplicate]

This question already has answers here:
Common breakpoints for media queries on a responsive site
(5 answers)
Closed 3 years ago.
I am working on a Responsive Web Site with CSS Media Queries.
Is the following a good organization for devices?
Phone, Ipad (Landscape & Portrait), Desktop and Laptop, Large Screen
What are the common media queries break-point values?
I am planning to use the following breakpoints:
320: Smartphone Portrait
481: Smartphone Landscape
641 or 768 ???: IPad Portrait ???
961: IPad Landscape / Small Laptop ???
1025: Desktop and Laptop
1281: Wide Screen
What do you think? I have a few doubts as ??? points.
Rather than try to target #media rules at specific devices, it is arguably more practical to base them on your particular layout instead. That is, gradually narrow your desktop browser window and observe the natural breakpoints for your content. It's different for every site. As long as the design flows well at each browser width, it should work pretty reliably on any screen size (and there are lots and lots of them out there.)
I've been using:
#media only screen and (min-width: 768px) {
/* tablets and desktop */
}
#media only screen and (max-width: 767px) {
/* phones */
}
#media only screen and (max-width: 767px) and (orientation: portrait) {
/* portrait phones */
}
It keeps things relatively simple and allows you to do something a bit different for phones in portrait mode (a lot of the time I find myself having to change various elements for them).
I'm using 4 break points but as ralph.m said each site is unique.
You should experiment. There are no magic breakpoints due to so many devices, screens, and resolutions.
Here is what I use as a template.
I'm checking the website for each breakpoint on different mobile devices and updating CSS for each element (ul, div, etc.) not displaying correctly for that breakpoint.
So far that was working on multiple responsive websites I've made.
/* SMARTPHONES PORTRAIT */
#media only screen and (min-width: 300px) {
}
/* SMARTPHONES LANDSCAPE */
#media only screen and (min-width: 480px) {
}
/* TABLETS PORTRAIT */
#media only screen and (min-width: 768px) {
}
/* TABLET LANDSCAPE / DESKTOP */
#media only screen and (min-width: 1024px) {
}
UPDATE
As per September 2015, I'm using a better one. I find out that these media queries breakpoints match many more devices and desktop screen resolutions.
Having all CSS for desktop on style.css
All media queries on responsive.css: all CSS for responsive menu + media break points
#media only screen and (min-width: 320px) and (max-width: 479px){ ... }
#media only screen and (min-width: 480px) and (max-width: 767px){ ... }
#media only screen and (min-width: 768px) and (max-width: 991px){ ... }
#media only screen and (min-width: 992px){ ... }
Update 2019: As per Hugo comment below, I removed max-width 1999px because of the new very wide screens.
This is from css-tricks link
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
#media only screen
and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
#media only screen
and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */
}
/* Desktops and laptops ----------- */
#media only screen
and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
#media only screen
and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
#media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
I can tell you I am using just a single breakpoint at 768 - that is min-width: 768px to serve tablets and desktops, and max-width: 767px to serve phones.
I haven't looked back since. It makes the responsive development easy and not a chore, and provides a reasonable experience on all devices at minimal cost to development time without the need to fear a new Android device with a new resolution you haven't factored in.
Media Queries for Standard Devices
In General for Mobile, Tablets, Desktop and Large Screens
1. Mobiles
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
2. Tablets
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
3. Desktops & laptops
#media only screen
and (min-width : 1224px) {
/* Styles */
}
4. Larger Screens
#media only screen
and (min-width : 1824px) {
/* Styles */
}
In Detail including landscape and portrait
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
#media only screen
and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
#media only screen
and (max-width : 320px) {
/* Styles */
}
/* Tablets, iPads (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
/* Tablets, iPads (landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
/* Tablets, iPads (portrait) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */
}
/* Desktops and laptops ----------- */
#media only screen
and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
#media only screen
and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
#media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
Reference
Consider using twitter bootstrap's break points.
with such a massive adoption rate you should be safe...
#media only screen and (min-width : 320px) and (max-width : 480px) {/*--- Mobile portrait ---*/}
#media only screen and (min-width : 480px) and (max-width : 595px) {/*--- Mobile landscape ---*/}
#media only screen and (min-width : 595px) and (max-width : 690px) {/*--- Small tablet portrait ---*/}
#media only screen and (min-width : 690px) and (max-width : 800px) {/*--- Tablet portrait ---*/}
#media only screen and (min-width : 800px) and (max-width : 1024px) {/*--- Small tablet landscape ---*/}
#media only screen and (min-width : 1024px) and (max-width : 1224px) {/*--- Tablet landscape --- */}
If you go to your google analytics you can see which screen resolutions your visitors to the website use:
Audience > Technology > Browser & OS > Screen Resolution ( in the menu above the stats)
My site gets about 5,000 visitors a month and the dimensions used for the free version of responsinator.com are pretty accurate summary of my visitors' screen resolutions.
This could save you from needing to be too perfectionistic.
I always use Desktop first, mobile first doesn't have highest priority does it? IE< 8 will show mobile css..
normal css here:
#media screen and (max-width: 768px) {}
#media screen and (max-width: 480px) {}
sometimes some custom sizes. I don't like bootstrap etc.
Instead of using pixels should use em or percentage as it is more adaptive and fluid, better not target devices target your content:
HTML5 rockrs read, mobile first
Keep your code clean and stylesheets logically separated per screen 'media' type config...
1) Using himansu's answer from above as a reference: Common CSS Media Queries Break Points
AND
2) https://www.w3schools.com/css/css3_mediaqueries.asp
your answer would be:
<link rel="stylesheet" media="#media only screen and (min-width : 320px) and (max-width : 480px)" href="mobilePortrait.css">
<link rel="stylesheet" media="#media only screen and (min-width : 481px) and (max-width : 595px)" href="mobileLandscape.css">
Your break points look really good. I've tried 768px on Samsung tablets and it goes beyond that, so I really like the 961px.
You don't necessarily need all of them if you use responsive CSS techniques, like % width/max-width for blocks and images (text as well).

Which are the most important media queries to use in creating mobile responsive design?

There are a lot different media queries for mobile screen sizes. It can be overwhelming to accomodate all of them when designing a responsive mobile site. Which are the most important ones to use when designing for mobile? I found this article that does a pretty good job of outlining the available media queries: http://css-tricks.com/snippets/css/media-queries-for-standard-devices/.
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
#media only screen
and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
#media only screen
and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */
}
/* Desktops and laptops ----------- */
#media only screen
and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
#media only screen
and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
#media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
I'd recommend taking after Twitter's Bootstrap with just these four media queries:
/* Landscape phones and down */
#media (max-width: 480px) { ... }
/* Landscape phone to portrait tablet */
#media (max-width: 767px) { ... }
/* Portrait tablet to landscape and desktop */
#media (min-width: 768px) and (max-width: 979px) { ... }
/* Large desktop */
#media (min-width: 1200px) { ... }
Edit: The original answer (above) was taken from Bootstrap version 2. Bootstrap has since changed their media queries in version 3. Notice that is there is no explicit query for devices smaller than 768px. This practice is sometimes called mobile-first. Everything outside of any media query is applied to all devices. Everything inside a media query block extends and overrides what is available globally as well as styles for all smaller devices. Think of it as progressive enhancement for responsive design.
/* Extra small devices (phones, less than 768px) */
/* No media query since this is the default in Bootstrap */
/* Small devices (tablets, 768px and up) */
#media (min-width: 768px) { ... }
/* Medium devices (desktops, 992px and up) */
#media (min-width: 992px) { ... }
/* Large devices (large desktops, 1200px and up) */
#media (min-width: 1200px) { ... }
Check it out on Bootstrap 3's docs.
Design in percentages and initially optimized for a 15"+ screen.
Review what components you want to see on a phone - just keep essential content and remove elements that don't work or clutter the small screen. These styles can be contained within #media (max-width: 480px) { ... }
As things move to 10" or less, redesign your buttons and interactive components for fingers rather than mouse. #media (max-width: 767px) { ... }
Shrink the width of your browser. When things don't look so good, get in to the console and figure out what styles can be changed or items that need to be redesigned or removed. Mark what screen width they occur at and create a media query.
At the end, review your media queries to see if some of them can be grouped together (ie if you have one at 750 and 767 pixels width, you might just as well with combining them in the 767).
If you are comfortable w jQuery you can add
$(window).resize(function(){
console.log($(window).width());
});
to get the current screen size. Add a few extra pixels for good measure.
The first Twitter Bootstrap code referenced by #cjlarose assumes that you've built your main CSS for a display that is between 980px and 1200px wide, so you're essentially starting with the desktop design and adapting all of the others from it.
I'm glad to see Twitter has changed to "mobile first" in Bootstrap 3. It's one of the most popular approaches to media queries, and the way I prefer to do it. You start from the smallest size rather than from the desktop out.
Note that your particular site may need different queries than what are listed there or on any other list. You should add queries as your content demands, not based on any set template.
Here are some media queries I've found most useful. These are just some examples:
/* Start with baseline CSS, for the smallest browsers.
Sometimes I put this into a separate css file and load it first.
These are the "mobile first" styles. */
...
/* Then progressively add bigger sizes from small to large */
/* Smartphones start somewhere around here */
#media (min-width: 300px) {
}
/* You might do landscape phones here if your content seems to need it */
#media (min-width: 450px) {
}
/* Starting into tablets somewhere in here */
#media (min-width: 600px) {
}
/* Perhaps bigger tablets */
#media (min-width: 750px) {
}
/* Desktop screen or landscape tablet */
#media (min-width: 900px) {
}
/* A bit bigger if you need some adjustments around here */
#media (min-width: 1100px) {
}
/* Widescreens */
#media (min-width: 1500px) {
}
The most important thing is that you may not need all of these, or you might want to change the numbers depending on what your content looks like. I don't think there are any really hard rules about how many or where to put your breakpoints. I'm doing a site right now that happens to only need one breakpoint because the content is pretty simple, but I've also done sites that look more like the code above.
I didn't include the retina display code. That's useful if you're switching out normal-resolution images for high-resolution images on hi-res displays, but otherwise it's not really that useful.

What are good resolution values to use with media queries?

Recently I've been playing around with CSS Media Queries because it's a great way to make my website adapt to various screen sizes. I am planning to implement them into the live version.
My question is: Are there any recommended resolution values at which the layout changes?
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").
I would just like to add to Suvi's answer.
Adaptive Design applies media queries to targeted resolutions however with Responsive Design you are free to add the breakpoints wherever you feel is necessary.
There is no rule as to how many breakpoints a page should have, but one should be added wherever the layout breaks. The aim is to make sure the design and content flows nicely regardless of the width of the viewport.
I think this post provides a good overview:
http://www.williamwalker.me/blog/an-introduction-to-responsive-design.html
Try this one with retina display
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
#media only screen
and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
#media only screen
and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */
}
/* Desktops and laptops ----------- */
#media only screen
and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
#media only screen
and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
#media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
Hope you are fine
I wrote this less solution:
/* screens range */
#screen-s-max: 20em; /* 320px */
#screen-min: 20.063em; /* 321px */
#screen-max: 40em; /* 640px */
#screen-m-min: 40.063em; /* 641px */
#screen-m-max: 64em; /* 1024px */
#screen-l-min: 64.063em; /* 1025px */
#screen-l-max: 90em; /* 1440px */
#screen-xl-min: 90.063em; /* 1441px */
#screen-xl-max: 120em; /* 1920px */
#screen-xxl-min: 120.063em; /* 1921px */
/*
0----- smallmobile -----320----- mobile -----640----- tablet -----1024----- notebook -----1440----- desktop -----1920----- wide
*/
#onlyScreen: ~"only screen";
#smallmobile: ~"(max-width: #{screen-s-max})";
#mobile: ~"(min-width: #{screen-s-max}) and (max-width: #{screen-max})";
#tablet: ~"(min-width: #{screen-m-min}) and (max-width: #{screen-m-max})";
#notebook: ~"(min-width: #{screen-l-min}) and (max-width: #{screen-l-max})";
#desktop: ~"(min-width: #{screen-xl-min}) and (max-width: #{screen-xl-max})";
#wide: ~"(min-width: #{screen-xxl-min})";
#portrait: ~"(orientation:portrait)";
#landscape: ~"(orientation:landscape)";
#highdensity: ~"only screen and (-webkit-min-device-pixel-ratio: 1.5)",
~"only screen and (min--moz-device-pixel-ratio: 1.5)",
~"only screen and (-o-min-device-pixel-ratio: 3/2)",
~"only screen and (min-device-pixel-ratio: 1.5)";
#mobile-and-more: ~"(min-width: #{screen-min})";
#tablet-and-more: ~"(min-width: #{screen-m-min})";
#notebook-and-more: ~"(min-width: #{screen-l-min})";
#desktop-and-more: ~"(min-width: #{screen-xl-min})";
/*
syntax example
#media #onlyScreen and #tablet and #portrait , #notebook and #landscape, #mobile and #landscape{
body{
opacity: 0.8;
}
}
*/
As shown in syntax example you can combine all these less variables and obtain complex media query. Use "and" for AND logic operator and comma for OR. You can combine different screen resolutions, device orientation (landscape/portrait) and retina or not devices.
This code is also easy configurable cause you can edit/add/remove screens range values to manage different screen resolutions.

Resources