Skip to main content

Command Palette

Search for a command to run...

Day 2 of conquering responsiveness

A summary of day 2 of conquering responsiveness by Kevin Powell

Published
2 min read

ems and rems

So today I pretty much learnt about ems and rems, the differences, the use cases and when one is preferred over the other.

So what are ems and rems?

These are units of measurements in css. em is a multiplier of its parent's element font-size while rem is a multiplier of its root element's font size. Check out CSS guides to learn the difference between root element, parent element and child.

When to use ems and when to use rems

rem units are a bit more consistent and scalable. This means that with rems for our font sizes, we are able to write few media queries as compared to using ems, and they won't compound on each other. The font-size is always looking at the root while the widths, margin, padding, heights, etc are looking at the font-size

Why you shouldn’t set font size using ems

ems compound on each other. When ems are used for font size, they look at their parent’s font-size to know what to be set to(referencing the parent font-size). This means that the font sizes won't be consistent in the page.

When do we use ems then?

Margins, paddings, widths, etc

ems set on anything other than font size do not reference the parent element. They reference the size of that element. So using ems on padding and margin helps with responsiveness and easy layout.

Check out this codepen link to help you play around with ems and rems on all the cases and see the results. Happy coding!

Knowing when to use ems and when to use rems, their differences, advantages of one over the other, helps with simple and easy css code as well avoiding writing many unnecessary media queries.

Reference

Z
zgd1y ago

We sincerely wish to purchase a well-established large-scale Multiplayer Online Role-Playing Game (MMORPG) mobile game developed by a reputable company. We intend to use it for study and research purposes in Asia. As a gesture of good faith, we are willing to pay a deposit upfront.If your friend has access to game source code, please let them know that I'll reward you for the referral.Interested parties, please contact me

EMail:q791864008q@gmail.com Discord:q791864008q_gmail_com Telegram:q791864008q_gmail_com

A

Keep up with the consistency!how about pixels on font size?

M

Pixels have fixed sizes