Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Because <code>em</code> is relative to the context.</p> <p>As <code>font-size</code> is inherited from the context, each descendant element with <code>em</code> <code>font-size</code> will multiply the current <code>font-size</code> up to the element that contains text content.</p> <p>Let's see in practice, assuming:</p> <pre><code>* { font-size: 3em } </code></pre> <p>You're applying that (relative to context) <code>font-size</code> to <strong>all</strong> elements.</p> <p>That means, the <code>html</code> element will have 3 times the default browser font-size. The <code>body</code> will have 3 times font-size of its container (<code>html</code>) which corresponds to 9 times the default font-size. And so forth for each element's ancestors.</p> <p>There's a new unit that does not have this issue, <code>rem</code> which is relative to root. But this is not as widely supported (no IE&lt;=8 support).</p> <hr> <p>Going a bit off-topic for the <code>em</code> x <code>px</code> x <code>rem</code> debate in this section of the answer.</p> <p>Quoting <a href="https://stackoverflow.com/a/609561/1331430">this answer</a>:</p> <blockquote> <p>Use <code>em</code> when you specifically want the size of something to depend on the current font size.</p> </blockquote> <p>Modern browsers can scale <code>px</code> units just fine. <code>em</code> was used mostly when old IE was predominant and didn't scale the <code>px</code> font-size when zooming.</p> <p>Still, <code>em</code> has it uses in web design. Say, when making CSS-icons that should scale relatively to the font-size of the text. But for overall layout, I go with <code>rem</code>/<code>px</code> which do not generate compound issues and headaches, or percentages when making fluid layouts.</p> <p>The issue with <code>px</code> for font-size is that, if you ever need to change the overall size of the page's text, you will have to change every single <code>font-size</code> declaration that uses <code>px</code>. That's where <code>rem</code> comes to aid.</p> <p>There's always an heated discussion about which unit to use for the <code>font-size</code>. Go with the one that gives less headaches and suffices for your project.</p> <p>So in sum, it depends on personal preference and project requirements.</p> <hr> <h2><em>References:</em></h2> <h3>Definitions and explanations</h3> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/length" rel="nofollow noreferrer">CSS Length units</a> - MDN</li> <li><a href="https://stackoverflow.com/q/609517/1331430">Why em instead of px?</a> - SO question</li> <li><a href="http://snook.ca/archives/html_and_css/font-size-with-rem" rel="nofollow noreferrer">Font sizing with rem</a> - Snook.ca</li> </ul> <h3>More discussions</h3> <ul> <li><a href="https://stackoverflow.com/q/11799236/1331430">Should I use px or rem in my css?</a> - SO question (recommends <code>px</code> for <code>font-size</code>)</li> <li><a href="http://css-tricks.com/why-ems/" rel="nofollow noreferrer">Why Ems?</a> - CSS-Tricks (recommends <code>em</code> for <code>font-size</code>)</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload