The Case for Using rem Units Over px on Your Website

Zachary Horvath

Zachary Horvath 2023-01-10 2 min read #softwareengineering

Are you using rem units for your font sizes in your web design projects? If not, you might want to consider it! Rem units offer a number of benefits that can make your work as a designer or developer easier and more efficient.

One of the main advantages of using rem units is that they are relative to the root element. This means that you can set the font size for an entire document using a single line of CSS. This can be especially useful if you want to change the overall font size of your site at a later point, as you only have to update the root element rather than every individual element on the page.

My portfolio website with medium (recommended) font-size enabled
My portfolio website using rem units with font-size "medium (recommended)" enabled in Chrome.

Another benefit of using rem units is that they are more flexible for responsive design. If the user increases the text size in their browser, the text size will adjust automatically with rem units (as opposed to px units, which won't respond to this change in settings). This can help to ensure that the layout remains readable and easy to use, even if the user has a preference for larger text sizes. This is especially important for users with visual impairments.

My portfolio website with very large font-size enabled
My portfolio website using rem units with font-size "very large" enabled in Chrome.

In addition to these benefits, rem units can also be easier to work with when you have nested elements. When you use rem units, the font size of child elements will be a fraction of the parent's font size. This makes it easier to create a consistent hierarchy and can be especially useful if you have a complex layout with multiple levels of nested elements.

Overall, using rem units for font sizes can make it easier to create a flexible, responsive layout and maintain a consistent hierarchy in your design. It can also help to ensure that your site is accessible for all users, which is an important consideration in today's digital landscape. So next time you're working on a web design project, give rem units a try and see the difference they can make.

Back