CSS Basics · Lesson 3 of 11

Fonts and Text

Most of a web page is text, so a handful of text properties do a lot of the work.

PropertyWhat it doesExample
font-familyThe typefacefont-family: Georgia, serif;
font-sizeHow big the text isfont-size: 20px;
font-weightHow boldfont-weight: bold;
text-alignLeft, center or righttext-align: center;
line-heightSpace between linesline-height: 1.6;

Font families

A visitor only sees a font if it is on their device, so font-family takes a list. The browser uses the first one it has:

body {
  font-family: Arial, Helvetica, sans-serif;
}

Always end the list with a general family: serif (letters with small feet, like in books), sans-serif (plain letters) or monospace (every letter the same width, like code).

Inheritance

Notice that rule is on body. Text properties are inherited: elements inside the body use the same font unless a rule says otherwise. Setting the font once on body styles the whole page.

Line height

A line-height of about 1.5 to 1.7 makes paragraphs much easier to read. The number is a multiple of the font size and has no unit.

Your Task

  1. Give the body a font-family list that ends in sans-serif.
  2. Center the <h1> with text-align.
  3. Make the paragraph text 18px with a line-height of 1.6.
  • The body rule sets a font-family that ends in sans-serif
  • The paragraph uses the same font as the body
  • The heading is centered
  • The paragraph text is 18px with a line height of 1.6