In this lesson, you sized the headings and lists of the seed swap page you built in HTML in rem, watched em sizes shrink at every level of a nested list, and saw rem follow the browser’s font size setting while pixels didn’t. Along the way, you met the Computed pane.
Key Points
- The Computed pane sits next to Styles in the Elements panel. It shows each property’s final value for the selected element, and font sizes show in pixels. Type
font-sizeinto its filter to see one property. The What to Bring heading started at 24 pixels. - Show all: with the
<html>element selected, the filtered list is empty. The browser’s own rules size headings, but nothing, not even the browser, sets the root’s font size. Check Show all to list every property, and leave it on. - The root’s font size is the font size of the
<html>element, 16 pixels by default. It comes from your browser’s font size setting, and the browser’s default sizes build on it. A heading’s 24 pixels is one and a half times 16. - rem: one rem is the root’s font size, so
1.25remis 1.25 × 16 = 20 pixels, and the Computed pane reads20px. - em, in
font-size, is the font size of the element’s parent, which is why rem is short for root em. Withli { font-size: 0.8em; }, Vegetables is 0.8 of 16, 12.8 pixels. Beans’ list sits inside Vegetables and takes on its 12.8 pixels, so Beans is 0.8 of 12.8, 10.24 pixels, and Runner beans is 8.192. - Watch out: with em, each nested item multiplies by 0.8 again, so the deeper it sits, the smaller it gets. With
0.8rem, every item is 12.8 pixels, however deep. - The visitor’s setting: in Chrome’s settings, under Appearance, Font size set to Very large is 24 pixels instead of 16. The root became 24 pixels, the headings 30 and the list items 19.2. Set Font size back to Medium (Recommended) when you’re done.
- Watch out:
1remand16pxonly match until a visitor changes the setting, and pixels ignore it. Headings written as20pxstayed at 20 pixels at Very large, smaller than the 24-pixel paragraphs under them. Zooming the page grows pixels too, but many people use the font size setting instead. - The rule: size text in rem. Every rem measures from the root, which follows the visitor’s setting as long as you don’t give
htmla font size in pixels, as inhtml { font-size: 16px; }. em suits things that grow with their own text, which you’ll meet with spacing. - Other units you’ll meet:
vwandvhare hundredths of the viewport’s width and height, the area the page is drawn in.%is a share of something that depends on the property, andchis the width of a zero in the current font, a rough guide to line length. They’re mostly for layout, which comes later.
Final Code
Rosa’s new list in events/seed-swap.html, after the What to Bring list: