[WEB] Which unit has the same value and result to any devices? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

[WEB] Which unit has the same value and result to any devices?

In my years of coding, I can't exactly find the HTML/CSS unit that would have exact the same size of elements. Just like the font-size, I tried the em unit because some says that it has the same value to any devices but I tried to use a smaller devices and it appears large and the texts are overlapping. Anyone who could suggest?

15th Aug 2018, 2:57 AM
Email Not Activated
2 Answers
+ 4
The problem with the em unit is that it depends on the font size of its parent element. The correct thing would be to use rem, as suggested by Kaimi, which is equivalent to 16px which is the default size that browsers assign to fonts (unless you change the size in the root element)
15th Aug 2018, 4:50 AM
Mickel
Mickel - avatar
0
There isn't a magical unit as the concentration of pixels per square unit varies across devices and may be disproportionate between the vertical and the horizontal. In website land, we rely on user agents to do the heavy lifting of calculating a rough translator to compensate for this. 'Pixels are perhaps best thought of as "device pixels" as this length doesn't have anything to do with the literal screen pixels in the display you are looking at. It's actually an angular measurement. It is supposed to be a value that is normalized across devices and displays, but that increasingly isn't true anymore.' The rest of the article gives a good overview of the different units ("absolute" and relative and odd ball, even though everything is essentially relative). https://css-tricks.com/the-lengths-of-css/ The cited/referenced article describes the nitty gritty about dpi/ppi. http://inamidst.com/stuff/notes/csspx Rough science/art.
15th Aug 2018, 5:07 AM
Janning⭐
Janning⭐ - avatar