MeltingDog MeltingDog - 2 months ago 14
CSS Question

What's the correct way to set a base REM value in CSS?

Sorry, I'm a little unsure of this.

I want my base to be 16px. But all the resources I read about rem use percentages, eg:

html { font-size: 62.5%; }
body { font-size: 1.4rem; } /* =14px */
h1 { font-size: 2.4rem; } /* =24px */

If I want all my rem sizes to be relative to 16px, do I just make
html { font-size: 16px; }

Why use percentages?


yes it's right. You need to make your html font-size to 16px as your base font-size and then use rem with the rest. Rem sizes the element relative only to html while em sizes relatively to its nearest parent.