DEV Community

Cover image for Using REM Doesn't Make Your Website Responsive - Here's Why

Using REM Doesn't Make Your Website Responsive - Here's Why

Caio Marcellus Cabral on August 30, 2023

You can access this article in portuguese here Você pode acessar este artigo em português aqui I love being part of technology communities. Besi...
Collapse
 
moopet profile image
Ben Sinclair

This reminds me of a university project where one of the requirements was a 10-page paper, so I kept upping the font size until it went onto 10 pages. I think when I handed it in it was 46pt.

I did not do well.

Collapse
 
franklivania profile image
Chibuzo Franklin Odigbo

This is very true. For more fluidity, I use em. And yes, you do not need media queries to make responsive sites. I use this a lot and when I show others the little media queries I use for responsiveness, they marvel 😅

Collapse
 
marcelluscaio profile image
Caio Marcellus Cabral • Edited

That's nice! I use em a lot on my paddings

Collapse
 
khair_al_anam profile image
Khair Alanam

Pretty insightful article on REM and responsiveness! I would also like to add that you can make the font-size responsive without using media-queries by using the clamp() function in CSS.

font-size: clamp(minimum_size, increment, maximum_size);

We set a minimum size for the text, and when we increase the screen size, the increment will do that font size increasing and then it will stop increasing when it reaches the maximum size.

It's supported by all the major browsers (except IE) so it's good to use.

Collapse
 
marcelluscaio profile image
Caio Marcellus Cabral

Excelent, Khair! I am actually going to talk about clamp() on the next article about fluid typography =D

Thank you for reading

Collapse
 
khair_al_anam profile image
Khair Alanam

You're welcome =D

Collapse
 
spo0q profile image
spO0q

As a backend dev who sometimes pretends to write CSS, I use clamp() and some linear function to keep things responsive.

I try to avoid rem but now I know why ^^. Thanks.

Collapse
 
marcelluscaio profile image
Caio Marcellus Cabral

Oh, clamp() is really useful, and I am going to talk about it on my next article, about fluid typography!

Thank you for reading =D

Collapse
 
spo0q profile image
spO0q

very nice. I'll read it!

Collapse
 
d7460n profile image
D7460N

Thank you for this article! Very informative.

CSS and typography are like two dancers along the Beautiful Blue Danube.

If I may, what are your thoughts on native intrinsic typography? Native, as in without dependencies.

Possible?

Collapse
 
marcelluscaio profile image
Caio Marcellus Cabral

Really happy you liked it!

About intrinsic typography, thank you for bringing it up! I hadn't read anything about it.

I'll delve into it

Collapse
 
techsnack profile image
TechSnack - Technology Tutorials

Great article. I work with responsiveness and accessibility mostly every day and I still learned something from this! Excellent work.

Also, are we going to dig into clamp next?

Collapse
 
marcelluscaio profile image
Caio Marcellus Cabral

Hey, TechSnack, I am really happy to read your comment!

Yeah, we are going to cover clamp and vw units on the next article on Fluid Typography. Hope you like the next one too =)

Collapse
 
techsnack profile image
TechSnack - Technology Tutorials

I bet I will enjoy it. I learned some of the deeper reasons behind why certain things are implicitly done the way the are.

I always enjoy having a deeper understanding of the why's and the how's rather than just the how.

Keep up the great work!

Collapse
 
drubb profile image
drubb • Edited

There are of course still use cases for absolute measurements like px.
Imagine a text paragraph on a small screen, with some horizontal padding. It would not make much sense to increase the padding with the font size, this would waste precious space. So in this case I'd still prefer px values for the padding.

Collapse
 
marcelluscaio profile image
Caio Marcellus Cabral

Oh, yes, drubb. I am mainly talking about font-sizes here. Of course in some properties you could use px, like border and box-shadow (even thoug you could use other units too).

For paddings I normally use em, and in some edge cases I could sprinkle some px, even though I propably would go for vw in that case you mentioned.

Thank you for reading and for the discussion =)

Collapse
 
artydev profile image
artydev

Very informative, thank you very much

Collapse
 
marcelluscaio profile image
Caio Marcellus Cabral

Thank you for reading =)

Collapse
 
artxe2 profile image
Yeom suyun

Using em as the default unit to create
responsive websites is incredibly convenient.
However, it does not respond to system fonts.

Collapse
 
marcelluscaio profile image
Caio Marcellus Cabral

It can help indeed, Yeom. I just wouldn't recomend using em for font sizes because a change to the HTML structure could ruin your typography system.

I love using em for paddings, for example, since it is always pointing to the same element.

Thank you for reading!

Collapse
 
wakywayne profile image
wakywayne

Very interesting, I had no idea that px were absolute like that!

Collapse
 
marcelluscaio profile image
Caio Marcellus Cabral

I'm happy it helped =)

Collapse
 
devdufutur profile image
Rudy Nappée

That's what happens when we use PX for font sizes: we ignore user preferences and impose the exact size we've chosen.

🤔🧐

Actually all modern browsers handle adapting font size in px according to user preferences...

px css unit doesn't actually rely on screen pixels but reference pixels, equivalent to 1/96 inches, meaning dependent to the density of screen in dpi but also the zoom level of the browser.

I don't really see a good reason using rem instead of px excepts increasing difficulty of code.

Collapse
 
stefanjudis profile image
Stefan Judis

Actually all modern browsers handle adapting font size in px according to user preferences...

I don't think that's true. I just tested Chrome and Firefox and neither adapt rendered font size defined in px to font default settings. Appearance -> Font size: very large (Chrome) or General -> Fonts -> Font size (Firefox) don't affect font sizes when they are defined in Pixels. Percentages or rem on the other hand do respect the default font size.

Image description

Collapse
 
devdufutur profile image
Rudy Nappée • Edited

Indeed my mistake. As mentionned in my reply to @marcelluscaio I was refering to zoom level, I didn't knew this font size setting.

Collapse
 
marcelluscaio profile image
Caio Marcellus Cabral

Great demo, Stefan! Interesting to notice that in font-sizes the percentage unit refers to the default font-size, so 100% is equivalent to 1rem

Collapse
 
marcelluscaio profile image
Caio Marcellus Cabral

Sorry, but that is not the case.

They do scale font with zoom, but if you set your font to pixels they are not going to adapt it to the user's font preferences.

So, you should not set your font size in pixels.

And I know it takes a while to adapt to writing in REM, but you eventually get used to it =)

And yeah, pixel actual size varies from device to device, due to screen density.

Collapse
 
devdufutur profile image
Rudy Nappée

What difference do you make between browser zoom and user preference ? Can you provide an example ? Thanks

Thread Thread
 
marcelluscaio profile image
Caio Marcellus Cabral

Changing the default size is like this: chromestory.com/2022/09/change-tex...

On the other hand, when you zoom in, browser adapts content, unless it is related to viewport size.

Again, using REM is not outdated in any way.

Thread Thread
 
devdufutur profile image
Rudy Nappée

Thanks for the precision, didn't knew this feature.

Collapse
 
khairunnisaas profile image
Khairunnisaas

ahh... learn something new everyday, thanks for sharing this!

Collapse
 
marcelluscaio profile image
Caio Marcellus Cabral

Thank you for reading =)

Collapse
 
malikbenkirane profile image
Malik Benkirane

for 1sec I thought this was about sleep and circadian patterns in human biology
maybe next time 😇

Collapse
 
marcelluscaio profile image
Caio Marcellus Cabral

Having a good night's sleep certainly helps with everything - including building better websites, Malik! xD

Collapse
 
samy profile image
Samuel Urah Yahaya

Nice and Informative!!! Picked up a few concepts from this.

Collapse
 
marcelluscaio profile image
Caio Marcellus Cabral

I'm happy to read that =)

Collapse
 
giuliano1993 profile image
Giuliano1993

This is a great article, probably the best explanation about how and why use rem i've ever read! I really appreciate that ( and also the rest of the article of course ) I will for sure apply what i read in my projects to come, thanks for this great work! 😁

Collapse
 
marcelluscaio profile image
Caio Marcellus Cabral

This comment fills me with joy =D

Thanks for reading and leaving a comment

Collapse
 
giuliano1993 profile image
Giuliano1993

Thank you for writing it! 😁
Really, I saved it to share to anyone needs a good explanatin about the topic 🙏
Hope to read more like this 😃

Collapse
 
davidecarpini profile image
Davide Carpini

Amazing article, you saved me lots of hours! I will save it between my favorites! thank you!

what are your thoughts on changing the root: element font size based on media query/clamp,
instead of changing each heading/text font size based on media query/clamp?
isn't it enough to change the root font size to make it responsive?

cheers!

Collapse
 
cleber_santana_97e23129a profile image
Cleber Sant'ana

I've been using and advocating for REM for years. But lately I feel It doesn't make much sense.

If users couldn't change font size and could only page zoom, no user would miss REM because page zooming on a px based site works just well as font resizing on a REM based site.

As a designer and developer, I do like the idea of having a unit the is related to the body font size and I think in REMs rather than in pixels. But in the real world,

  • REMs create one more barrier between design and dev teams.
  • Font size options are buried in the browser settings while page zooming is always at hand (to be fair, my wife's smartphone asked if she'd like to change font size for the whole system when It was first booted. And she changed it!)
  • Even some epub readers that have widgets for changing the font size actually zoom in under the hood
Collapse
 
marcelluscaio profile image
Caio Marcellus Cabral

But the point is setting the custom font-size instead of having to zoom all the time. I see it as a really low hanging fruit, and it is one more possibility for our users, no need to take that away from them

Collapse
 
dthrt profile image
Dmitriy Yoo

Amazing article! Thank you! 😄👍

Collapse
 
aaron_mendoza_90c47169176 profile image
Aaron Mendoza

Thank you so much!! Very informative. Looking forward to reading the clamp() article.