Coursify
Create New CourseGalleryContact

E

Unit 1
Em
Introduction to Ems
Unit 3 • Chapter 2

Em in CSS

Video Summary

In CSS, the "em" unit is a relative length unit that's relative to the font size of the element it's applied to. If you set the font-size of an element to 16px and then set the width of a child element to 2em, that child element will have a width of 32px (16px * 2). This relative nature makes 'em' useful for creating scalable and flexible layouts. However, it's important to be aware of inheritance. The 'em' unit inherits the font size from its parent element, leading to potential cascading effects across the page, which can sometimes make it challenging to precisely control dimensions. Therefore, careful consideration of font sizes and nested elements is crucial when using 'em' to maintain predictable visual outcomes. Unlike fixed units like pixels, the 'em' unit adjusts proportionally with the user's browser settings for font size, improving accessibility for users with customized font preferences. For consistent sizing independent of parent font size, consider using the 'rem' unit (root em), which refers to the font size of the root element (usually the <html> element).

Knowledge Check

What is the CSS unit 'em' relative to?

If the parent element has a font-size of 14px and a child element has a width of 2em, what is the child element's width?

Which unit is generally preferred for consistent sizing independent of parent font size?

What is a potential challenge when using the 'em' unit for layout?