liveBook · Manning

Font-size property

As explained in Web Design Playground

A CSS property that sets the size of text.

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

How Web Design Playground covers it

How deep it goes
Explains pixel declarations and inherited em sizing, while deferring the full range of CSS units.
Examples
Uses a 36px heading rule, a 24px div, and nested body, header, and heading em rules.
What it assumes
Teaches CSS rule syntax from its parts and introduces pixel sizing before addressing relative units.
What you can do after
Operate/configure it to set shared heading sizes and choose relative sizes that respond to browser font settings.
How it connects
Connects CSS selectors and style rules with browser defaults, relative units, inheritance, and responsive typography.

Also explained in

Compare how 9 books explain font-size property →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground. The section links point to the parts of the book it draws on.