The font-size base is determined by predefined user preferences in the browser.
In almost every browser, 16px is the standard for proportional fonts. This may also vary depending on whether a serif font or a fixed-width font is used.
In most projects, I usually set the html element to use the px value instead of the % or em/rem value only so that all browsers, screens and devices have the same font size and that the elements on the page have the same sizes and proportions.
Just remember that using em takes font-size parents in proportion to this, while rem uses html root elements
For instance:
html { font-size: 16px; } h1 { font-size: 2em; // 32px } p { font-size: 1em; // 16px } .someClass { font-size: .75em; // 12px } .someClass p { font-size: 2em; // 24px } .someClass p .test { font-size: 1.25rem; // 20px }
<html> <h1>2em Title Text</h1> <p>Normal Element Text</p> <div class="someClass"> someClass font size <p>SomeClass with em</p> <p><span class="test">someClass p element with class test</span> </p> </div> </html>
source share