Skip to content
FORGENO ADS GAMESUnlock all $8

CSS · Unit 1: Styling basics · Lesson 4 of 5

Fonts and text

font-family picks a typeface.

Opens this lesson in Code Academy. Lessons open one after another, and each unit opens when you pass the checkpoint quiz before it (you can take a checkpoint early to skip ahead). If this lesson is not open yet, the button shows you its unit on your map.

The idea

font-family picks a typeface. List a few, ending with a generic family in case the first ones are not installed: font-family: Georgia, serif;

font-size sets the size and font-weight sets the boldness (400 is normal, 700 is bold). line-height sets the space between lines; a plain number like 1.5 scales with the text.

text-align lines text up: left, center or right. Center works for short headings; long paragraphs read best left-aligned.

Worked example

CSS

h1 {
  font-family: Georgia, serif;
  text-align: center;
}

p {
  font-size: 18px;
  line-height: 1.6;
}

The HTML it styles

<h1>Recipes</h1>
<p>Simple food for busy days. Every recipe takes under 30 minutes.</p>

Key terms

Font properties
font-family, font-size, font-weight, line-height and text-align control how text looks.

Practise it in Code Academy

It has 4 exercises (multiple choice, fill in the blank, fix the broken code and write code from a prompt) and takes about 6 minutes. Every answer is checked as you go, and feedback names the exact mistake. Hints and the solution are there if you get stuck.

Every lesson is free: no ads, no lives and no paywall.