I have a simple question, where do you declare the base size that rem
is calculated from?
<body>
<h1>Something</h1>
</body>
I can see that the font-size
is <body>
is set to 16px and the <h1>
is set to 3rem
, yet the font is rendering at 30px when I'd expect 48px. Can any parent redefine the base?
rem
units are based on the font-size of thehtml
element, not thebody
element. The default size is usually 16px on html, however that's not guaranteed, and users can change that default value. A common practice is to manually set the font-size explicitly on html, usually to that 16px value, and then use rems in other places to set the final display value.However, that practice has accessibility problems for when users want or need to increase the default font size, so you should design your pages and layouts so that they can adapt to different sizes.
From https://developer.mozilla.org/en-US/docs/Web/CSS/font-size:
Source
In other words, change the font size of your
html
element, and the calculation base forrem
will change.