Okay, first off, yes I have read many many articles (Should I use px or rem value units in my CSS?) and forums about this.
I know that 1px is not a physical pixel but rather a CSS pixel, and rem
is basically the same as em
, but it is relative to the root element (hence the r in rem - root), rather than the parent element. em
itself is equal to the size set in the document, and it is popular due to the scalability in comparison with pixel, which cannot be scaled.
In all articles I read that everyone loves rem, and it should be used for font-size
in modern browser, but also use px
as a fall back for IE8 and lower. I see the main reason people use rem is so that the size scales better and is more "mobile friendly".
Now suddenly I read articles saying that all modern browsers support viewport
, so scalibilty is no longer that big of an issue.
Then I read to properly convert rem to px and vice versa, we can use html { font-size: 62.5%; }
which then turns 1rem to 10px.
So after all this confusion, if scalibilty is no issue because of viewports and 1rem is converted to 10px via html 62.5%, plus I will use pixels as a fall back anyway, then why use rem in the first place and not just stick with pixel? I don't see any advantages of using rem
anymore.
Or did I miss some major advantage of rem
?
Using REM (or another relative length value) for font-size is a must for accessibility, because px in some browsers doesn't resize when the browser settings are changed. Some people, for example, need to zoom maybe up to 400% to be able to read your text, due to a visual impairment.
We should use rems or em because they are based on font-size. It may seem a bit strange but by doing so we can build more robust responsive layouts because just by changing font sizes, we will automatically change length.
Use em only for sizing that needs to scale based on the font size of an element other than the html (root) element. Use rem unit for elements that scale depending on a user's browser font size settings. Use rem as the unit for most of your property value.
EM is relative to the parent element's font size, so if you wish to scale the element's size based on its parent's size, use EM. REM is relative to the root (HTML) font size, so if you wish to scale the element's size based on the root size, no matter what the parent size is, use REM.
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.em
, in other words, it scales rem
and px
equally.rem
is supported by all major browsers on desktop and mobile devices. px
as fall back option for IE8 and lower.font-size
of 16px (feel free to Google yourself), which equals to 1rem
/em
px
and rem
you can use html {font-size: 62.5%;}
which converts 10px
to 1rem
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With