Faqs And TroubleshootingFAQs
Should I use Pixel, Rem, or Em?
2 min read
Introduction to pixel, rem, and em
What is px (pixel)?
Different devices have a different number of pixels per inch on their screens, this is known as pixel density. Although the size of a pixel isn't always the same, the font-size, margin, and padding in pixel (px) remain the same for all the screens.
What is em?
Em is a relatively flexible and scalable unit of typography. Because CSS is cascading and inheritable, em will inherit font-size value from the parent element.
What is rem?
When should you use one unit over another?
- Font size: Now px and rem basically have the same effect on the text; as we would get the same result if we used 32px and 2rem. This is because the default root font-size is 16px.
- Padding and margin: Because of the inheritable, em unit will be helpful for padding and margin. By using em, we can make the padding and margin scale proportionately.
- Border width: both rem, em, and px can be used based on your use case. Most of cases, px is recommended since the value we give to the border width is so small that it is almost not noticeable if we change the root font-size.
Last updated