Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with "font-size": recommend to users not to set font-size with "em" units #14282

Closed
queengooborg opened this issue Mar 25, 2022 · 3 comments
Labels
Content:CSS Cascading Style Sheets docs

Comments

@queengooborg
Copy link
Collaborator

queengooborg commented Mar 25, 2022

MDN URL: https://developer.mozilla.org/en-US/docs/Web/CSS/font-size

A user in the MDN Web Docs Matrix room commented about how the mdn/css-examples repo defines its body font sizes with the em unit (that is, the interactive example at the top of the page).

Using em to define a font size isn't a good practice, because ems are based upon the font size -- in other words, this is setting a font size to...well, relative to the parent's font size. On the body, this isn't as big of an issue, but say you set font-size: 1.25em on something like div, which can have many children: now, each child div is going to have a font size of 125% relative to its parent's font size, creating a constantly-growing font size.

I think that the example shouldn't include an em as one of its default options, especially not as the first option. I also think that we should update the MDN page to include a note at the top to state as such and add a section to explain why.

I found a video that explains why to avoid ems as a font size, which I used as a reference for this.

MDN Content page report details
@queengooborg queengooborg added Content:CSS Cascading Style Sheets docs needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Mar 25, 2022
@sideshowbarker sideshowbarker removed the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Mar 25, 2022
@wbamberg
Copy link
Collaborator

wbamberg commented May 6, 2022

@queengooborg when you say:

the mdn/css-examples repo defines its body font sizes with the em unit.

...are you referring to the interactive example at the top of the page?

@queengooborg
Copy link
Collaborator Author

Yes, I'm referring to the interactive example at the top of the page!

@Josh-Cena
Copy link
Member

We already fully explain the em compounding pitfall on this page (from the very start) and mdn/interactive-examples#2604 fixed the example. I'll consider it done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:CSS Cascading Style Sheets docs
Projects
None yet
Development

No branches or pull requests

5 participants