DEV Community

Discussion on: 🛑 Stop using pixels in CSS

Collapse
 
aleksandrhovhannisyan profile image
Aleksandr Hovhannisyan

Oh lord... That Twitter thread has so much misinformation.

  1. There is no reason to exclusively use rem over em. In fact, what you usually want is em because an element's padding and margins are 100% dependent on that element's own size. Elements with larger text will need to scale their spacing accordingly. Good luck doing that with rem if you ever need to change an element's font size.

  2. em allows you to style local regions of a page with greater ease. rem always resets you back to the root font size. This is annoying (see #1).

  3. Both em and rem can be used for responsive typography. I saw this point come up a lot, where people argue that rem is better. No—no it's not. There's no difference. As long as you use ems consistently from top to bottom, your UI will still scale, just as it would with rem.

  4. rem and em both have their uses. There's no reason to choose one over the other exclusively, though I find myself using em far more often (#1-3).

Collapse
 
dailydevtips1 profile image
Chris Bongers

I don't think that's the point, it's more about using rem or em, I personally use rem, but em would work just as well.

I do thank you for this detailed explanation, wasn't aware of these points in rem vs em.

So is there any case that you still use pixels?
(Media-queries/borders?)

Collapse
 
aleksandrhovhannisyan profile image
Aleksandr Hovhannisyan

Yup! I still use pixels for borders and border radii. I also use them for media queries, though it really depends on where the breakpoint falls. If it falls within a screen width where my font is still scaling up/down responsively between two extremes that I've set up, then I'll use pixels to be more precise.

Thread Thread
 
dailydevtips1 profile image
Chris Bongers

Oke makes sense yes!