What are the disadvantages of vh and vw units?

Viewed 351

I am pretty new to front-end development. I wonder what are the disadvantages of vh and vw? I have been always using them because they can adjust the font size based on the screen size. However, I didn't see many people use them as much as I do and saw online that most people prefer to use em. So, it is okay to keep always using vh and vw? What are their disadvantages?

Thank you very much!

1 Answers

The disadvantage is the same as the advantage: it is relative to the screen dimensions.

This is something you probably don't want for a font, since "absolute" units like px and cm already are relative to the perceived size*, which accounts for how distant the observer is from the screen. For example: If a user is using a mobile phone to navigate a web page, you would want the font size to remain constant whether it has a big screen or a small screen.

So I would recommend using an absolute unit like px to set the font size, border thicknesses, etc...


* According to the spec. In practice, the size of px is often synchronized with the OS settings.

Related