CSS Fonts
You already style how text sits on the line. Fonts choose which letters you see — the typeface family, how large they are, how bold, and whether they lean italic. Loading custom web fonts comes in the next lesson; here you master the core font properties.
Font tools at a glance
📊 Common font properties
| Property | Everyday job |
|---|---|
font-family |
Names the typeface stack (plus a generic fallback) |
font-size |
Sets how large the text is |
font-weight |
Sets how bold the text is (e.g. 400, 700, bold) |
font-style |
Sets normal or italic (and related styles) |
font (shorthand) |
Combines style, weight, size, and family in one declaration |
Font family stacks
List preferred fonts first, then safer alternatives, and end with a generic family like sans-serif or serif so something always draws.
Readable sans-serif stack
cssbody {
font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
Font size
font-size sets the size of the text. Relative units like rem often scale more calmly with the page; px and keywords like large also work.
Heading and body sizes
cssh1 {
font-size: 2rem;
}
p {
font-size: 1rem;
}
Font weight
font-weight controls boldness. Numeric weights (400, 700) or keywords (normal, bold) are common. The face must support the weight you ask for.
Emphasize with weight
css.lead {
font-weight: 700;
}
.caption {
font-weight: 400;
}
Font style — italic
font-style: italic leans the text when an italic face is available. Use it for quotes or soft emphasis, not for every paragraph.
Italic quote
cssblockquote {
font-style: italic;
font-family: Georgia, "Times New Roman", serif;
}
Font shorthand
The font shorthand can set style, weight, size, and family together. Size and family are required in the shorthand form most browsers expect.
Font shorthand on a card title
css.card-title {
font: italic 700 1.25rem Georgia, "Times New Roman", serif;
}
A calm body habit
Pick one clear stack for the page, a slightly stronger weight or size for headings, and keep body text easy to read.
Page font baseline
cssbody {
font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
font-size: 1rem;
font-weight: 400;
line-height: 1.6;
}
h2 {
font-family: Georgia, "Times New Roman", serif;
font-size: 1.5rem;
font-weight: 700;
}
Try it yourself
- Set
bodyto a sans-serif stack that ends withsans-serif. - Give
h1a largerfont-sizeandfont-weight: 700. - Style a
blockquotewithfont-style: italicand a serif stack. - Rewrite a heading using the
fontshorthand. - Compare the same paragraph in serif vs sans-serif — notice the mood change.
Common mistakes
- Naming one fancy font with no fallback (broken look when that face is missing)
- Setting enormous fixed
pxsizes everywhere with no relative thinking - Asking for
font-weight: 900when the face only ships regular and bold - Jumping into
@font-face/ hosted web fonts here (next lesson) - Using text-align or text-decoration when you meant font-family or font-weight
Summary
font-familylists a stack and should end with a generic familyfont-sizesets text size; relative units often scale calmlyfont-weightandfont-styleadd bold and italic emphasis- The
fontshorthand packs style, weight, size, and family - Keep a clear body stack; save custom web font loading for the next lesson
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top