There is one main reason why to use EM based media queries and that is
respect the users (base) font size setting
without breaking your layout!
You really should never ever neither define font-sizes in pixel (nor your elements width/height)!!!
Let the user decide what font-size he likes to look at your site.
So it is a question of accessibility.
If you are using pixel values, you have to assume a certain (base) font size, which is "normally" 16px. But not always, and that's the point. So if an user has chosen a smaller or larger (base) font size, your layout will fall apart.
Or on desktop systems, if the user uses the browser's zoom function he will get a horizontal scrollbar (which is mostly undesired).
All of this can be avoided by using relative units like EMs
. And they have no drawbacks.
It is also worth mentioning that actually the base font size setting, as well as the zoom functionality in mobile browsers (on touch devices like tablets and samrtphones) work differently compared to their desktop counterparts. For the mobile browser versions the font size setting doesn't play such an important role as for desktop browsers. But again you do nothing wrong by using EM
based media queries. And imho this is as "future proofed" as possible.
And you can easily use the "62.5% technique" as well.
Be reminded that the new "root em" font size depends on the root element's (of the page) font size and that is the html
element, not the body
element.
Use the "62.5% technique" without breaking accessibility:
html {
font-size: 62.5%; /* with the standard base font size of 16px this will be equal to 10px */
}
body {
font-size: 160%; /* 160% of 10px ~ 16px, understood by all browsers */
font-size: 1.6rem; /* 1.6 * 10px ~ 16px, understood by all major browsers and IE9+ */
}
So you can use rem
just as if it where px
(divided by 10),
but without doing any harm to the user's settings!
No matter what base font size the user has chosen the font ratio will always stay intact.
And also your layout! ;-)
One final remark:
Always use min|max-width
media queries and never device-width
! The reason in short is that you layout and setting your breakpoints depending on your content and never on resolutions of any devices!
So by using relative units (like EMs
) for your layout and font sizes your design is really "responsive". By using absolute units (like PX
) it is not!