Don’t use px!

px is a useful format when you’re writing a document in Word, for example. As long as no one has zoomed in or out, then you know that if you make your font size 10px then it’s going to be small and 20px will be big. 12px is pretty nice to read and it’s…


This content originally appeared on DEV Community and was authored by Nic

px is a useful format when you're writing a document in Word, for example. As long as no one has zoomed in or out, then you know that if you make your font size 10px then it's going to be small and 20px will be big. 12px is pretty nice to read and it's not complicated.

It is on the web, though.

The default font size on browsers on computers tends to be 16px. So in theory you could set your font size to be 16px, and if you want small text 12px is fine and for big text 20px is fine. Except it's not.

16px is merely the default font size. It's possible for users to change that and make it smaller or bigger. So if someone finds that 16px text is too small to read is not going to be able to read 12px. And someone who finds that 16px is just too big will find 20px absolutely huge.

Which is why relative units are a better idea (em or rem). So on most browsers, 1em = 16px. But for our users above, 1em could = 20px or 12px. You just don't know who is looking at your website and what setup they have - you want it to be readable by everyone. So set your font sizes using em or rem, rather than px.

If you want to know about the difference between em and rem, Kevin Powell has a video that explains it with examples.

This rule also applies to line-height. A line height of 18px might sound like there's plenty of space between the lines of text, but our users could find that it's all squished up or too spaced out, both of which make it hard to read. line-height is best used as a fraction. So a line-height of 1 means same as the font size. A line-height of 1.5 is 1.5 * font-size.

(This post brought to you by me seeing too many sites hard coded to be 12px and since I am the user who finds 16px too small, 12px is tiny in my browser)


This content originally appeared on DEV Community and was authored by Nic


Print Share Comment Cite Upload Translate Updates
APA

Nic | Sciencx (2021-06-19T09:45:27+00:00) Don’t use px!. Retrieved from https://www.scien.cx/2021/06/19/dont-use-px/

MLA
" » Don’t use px!." Nic | Sciencx - Saturday June 19, 2021, https://www.scien.cx/2021/06/19/dont-use-px/
HARVARD
Nic | Sciencx Saturday June 19, 2021 » Don’t use px!., viewed ,<https://www.scien.cx/2021/06/19/dont-use-px/>
VANCOUVER
Nic | Sciencx - » Don’t use px!. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/19/dont-use-px/
CHICAGO
" » Don’t use px!." Nic | Sciencx - Accessed . https://www.scien.cx/2021/06/19/dont-use-px/
IEEE
" » Don’t use px!." Nic | Sciencx [Online]. Available: https://www.scien.cx/2021/06/19/dont-use-px/. [Accessed: ]
rf:citation
» Don’t use px! | Nic | Sciencx | https://www.scien.cx/2021/06/19/dont-use-px/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.