4

I know about two reasons why we used to use em or rem for font sizes:

  • Some obsolete browsers could not zoom the page otherwise and
  • Some websites roll their own zoom controls (because the designer was unaware of the browser functionality or wanted it more prominent or whatever) by changing the font size of the body

None of those are real reasons on a modern website with a reasonably tech-savvy user base.

Are there any real reasons to still use em or rem instead of for examle px? px for example has the advantage of being a unit that directly conveys what the text would approximately look like.

Is there some functionality that would break? Some relation with screen DPI settings or the like? I am only asking about settings that I could try out right now on a recent Chrome, Firefox or Safari on Windows, Android or iOS... not about some obscure browsers or niche systems.

AndreKR
  • 32,613
  • 18
  • 106
  • 168
  • IMO, it mainly depends on the units you use on your document : if every of your units are relatives, it makes more sense to use relative units for font-size as well, if they're absolute however, it makes more sense to use absolute ones – Kaiido Aug 22 '15 at 06:25
  • Check out these sites :) btw I never ever use em, only px's https://css-tricks.com/why-ems/ - http://www.quora.com/When-should-you-use-em-over-pixels-in-CSS – James111 Aug 22 '15 at 06:37

2 Answers2

1

I really like using em to size texts. I don't have to bother about the user's preferences, but my design will keep its proportions (using em not only for fonts, but the whole layout).

As stated in this A List Apart article:

The em is a true typographic unit, recommended by the W3C, and affords a precision keywords lack.

There is even a full article on building complete layouts based on em: Responsive Webdesign by Ethan Marcotte

Mischback
  • 843
  • 5
  • 18
  • I agree, and I especially like using em for fonts in responsive slideshows, because without it they tend to display the text on top of a slide incorrectly on various devices and screen sizes. Using em I can position and size things so everyone sees the same thing – Scott Dallas Aug 22 '15 at 11:49
-3

CSS Font-Size: em vs. px vs. pt vs. percent

http://kyleschaeffer.com/development/css-font-size-em-vs-px-vs-pt-vs/

Why em instead of px?

Community
  • 1
  • 1
Girish Jha
  • 132
  • 5
  • I found that article before, but it claims that "we’ve decided that point and pixel units are not best suited for web documents" based on the fact that it would break when one sets `body { font-size: 120% }` - why would anyone ever do something like that? – AndreKR Aug 22 '15 at 06:10
  • That article was also one reason why I excluded that case explicitely in my question title. – AndreKR Aug 22 '15 at 06:11
  • 1
    @Girish Jha even if the page linked does answer the question, please insert the valuable info into your answer. – Kaiido Aug 22 '15 at 06:16
  • @Kaiido If by that you mean that "Pixels are now considered acceptable font size units" answers my question with "No reason anymore", you should make that an answer. If you mean that "they are starting to cause some issues" answers my question with "Yes, the reasons are ..." you should also make that an answer elaborating on the issues. – AndreKR Aug 22 '15 at 06:20
  • @AndreKR I'm not well placed enough to make a real correct answer so I prefer to keep silent. I was just pointing that the article linked does talk about dpi which may cause issues with `px` unit. – Kaiido Aug 22 '15 at 06:23
  • @Kaiido Fair enough. Maybe someone else will chime in. – AndreKR Aug 22 '15 at 06:24