Which is the best way to set the size of text on CSS and why? em, rem, px, %, vw or vh? Thank you, people! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Which is the best way to set the size of text on CSS and why? em, rem, px, %, vw or vh? Thank you, people!

6th Jul 2018, 1:57 PM
Celeste Zapata
Celeste Zapata - avatar
3 Answers
+ 1
Understanding what they all do is important. For a beginner, I recommend having your main font-size in px and setting heading levels in em to keep things simple. After that, I think it's a matter of preference. (There are some pretty fierce champions of different setups. Search: "62.5% rule" for some entertainment.) If you're using a library that you didn't create, you'll need to understand the units the library uses (e.g. dp in React). I hope this helps! ☺
6th Jul 2018, 4:37 PM
Janning⭐
Janning⭐ - avatar
+ 10
it depends on user screen display.. but i use px most of time😅
6th Jul 2018, 2:00 PM
Jaydeep Khatri
Jaydeep Khatri - avatar
+ 5
For responsive design, it's best to use rem, but rem has compatibility issues with older version browsers. The best dimension to use now is em. Use % or vw for making screen width proportion. Use vh for screen height proportion.
6th Jul 2018, 2:15 PM
Calviղ
Calviղ - avatar