Why use rem instead px when it's the same anyway?
So after all the research, I came to the conclusion that the only advantage of rem
, is that users who use a bigger default font-size in their browser setting, will get the font-size scaled properly, while px
will not scale. In other words, using rem
for font-size
, adds support for Accessibility to your website.
To sum up:
rem
is a way to add support for Accessibility to your website.- Keep in mind, most users use zoom instead of font-size change in their browser and phones, because zoom easier to access.
- Browser zoom has additonal affect on
em
, in other words, it scalesrem
andpx
equally. - Since 2012,
rem
is supported by all major browsers on desktop and mobile devices. - Use
px
as fall back option for IE8 and lower. - Although not specified by W3C, all browser across desktop and mobile devices have implemented a default
font-size
of 16px (feel free to Google yourself), which equals to 1rem
/em
- To make the conversion easier between
px
andrem
you can usehtml {font-size: 62.5%;}
which converts10px
to1rem
In one sentence: Use rem
with px
on font-size
to support accessibility.
html {
font-size: 62.5%;
}
.your_class {
font-size: 16px;
font-size: 1.6rem;
}
The 62.5% only works if the browser's default font-size
is left at the default 16px
. Just because you, as a normal able-bodied person (or at least a person with normal eyesight) have the default settings for font-size
, you cannot assume that holds true for the populace at large.
Consider those with poor eyesight. In their case, they'll have their font-size set to 20px, or maybe 28px for very poor eyesight. If everything is maintained in px
, then your display isn't going to be mutable for those with different needs. Content will overflow its containers and your website will look broken.
Or, maybe you can relate to having a piece-of-junk computer at the place where you work. We used to have old 800x600 monitors on a factory floor at my first job. Default font-size on those was 10px. Websites looked horrible on them, and it was because everyone expected the content in their site's content to consume much more space than it actually did.
The obvious solution is to make the layout respond to the content. font-size
is one of the few elements that a browser will bring to the table on its own based on the preference of its user. Since that user is your audience, you'd do well to respect their preference as you want them to continue visiting your site, and not hate using it when they do.
Just my 2¢ (and, well, the actual reason that people push for rem
as opposed to px
).