Want your headings to stand out or your body text to be easier to read? The CSS font-size property sets the size of an element’s text. Browsers supply default sizes, but you can choose your own for headings, paragraphs, captions, and more. section 4.9
Set a heading size
h1 { font-size: 36px; } The selector h1 chooses every first-level heading on the page. The declaration sets its text to 36 pixels; px means pixels. If you want those headings larger later, change the value once rather than editing each heading. section 1.19
To make your own rule:
- Choose an element with a selector, such as h1 or div. section 1.17
- Inside braces, write font-size: followed by a value and a semicolon, such as font-size: 24px;. section 4.9 section 1.17
Pixels aren’t your only option. A relative unit such as em can respond to a visitor’s chosen default font size. That matters when someone increases their browser’s default to make text easier to read. Watch out, though: font-size is inherited, so nested em sizes can build on a parent’s size rather than the browser default. section 14.7
body {
font-size: 1em;
}
header {
font-size: 1.5em;
}
h1 {
font-size: 2em;
}
Follow the sizes from body to header to h1. With a 16px default, the header’s 1.5em is 24px, and the heading’s 2em builds on that to become 48px—not 32px. section 14.7
Your turn: write a rule that makes every second-level heading 30 pixels tall. Then try changing the value and see how all those headings change together. section 1.19








