On this page10 sections
  1. Learning Objectives
  2. 1. Alignment
  3. 2. Line Height
  4. 3. Case, Decoration and Spacing
  5. 4. Styling Links
  6. 5. Text Shadow
  7. Common Beginner Mistakes
  8. Practice Questions
  9. Practice Answers
  10. Key Takeaways

Lecture 009: Styling Text

Category3: Text, Fonts & Content
Lecture009 of 057
Estimated video length12 min
TargetCSS3 · any modern browser
LevelBeginner

Most of a page is text, so small text settings make a big difference: alignment, line spacing, capitals, underlines. This lecture covers the properties that make text comfortable to read.


Learning Objectives

  • Align text with text-align
  • Improve readability with line-height and letter-spacing
  • Change case with text-transform and underlines with text-decoration
  • Style links, and add text-shadow

1. Alignment

Example

html
<style>
  p { background: #f1f3f5; padding: 6px; }
</style>

<p style="text-align: left;">Left (the default)</p>
<p style="text-align: center;">Centre</p>
<p style="text-align: right;">Right</p>
<p style="text-align: justify;">Justify stretches the spaces so every full line reaches both edges, like a newspaper column. It can leave odd gaps in narrow boxes.</p>

Centre short things such as headings and buttons. Keep paragraphs left-aligned; they're easier to read.


2. Line Height

line-height sets the space between lines. A plain number such as 1.6 means "1.6 times the font size".

Example

html
<p style="line-height: 1;">line-height 1 is cramped. The lines almost touch each other, which makes long paragraphs hard to follow.</p>
<p style="line-height: 1.6;">line-height 1.6 is comfortable. Each line has room to breathe, so the eye moves easily to the next one.</p>

1.5–1.7 is a good range for body text.


3. Case, Decoration and Spacing

Example

html
<style>
  .upper  { text-transform: uppercase; letter-spacing: 2px; }
  .cap    { text-transform: capitalize; }
  .strike { text-decoration: line-through; }
  .wave   { text-decoration: underline wavy #e03131; }
  .indent { text-indent: 2em; }
</style>

<p class="upper">small label</p>
<p class="cap">every word gets a capital</p>
<p class="strike">Cancelled</p>
<p class="wave">Spelling mistake</p>
<p class="indent">The first line of this paragraph is indented, like a printed book.</p>

Links have states, which you'll study in Lecture 020. The most common look:

Example

html
<style>
  a { color: #1971c2; text-decoration: none; }
  a:hover { text-decoration: underline; }
</style>

<p>Read the <a href="#">delivery policy</a> before ordering.</p>

Make sure links still look like links: a different colour, plus an underline on hover.


5. Text Shadow

text-shadow: x y blur colour;

Example

html
<style>
  h1 { color: white; background: #364fc7; padding: 16px; text-shadow: 2px 2px 4px rgb(0 0 0 / 0.5); }
</style>

<h1>Big Sale</h1>

Use it lightly. Heavy shadows make text harder to read.


Common Beginner Mistakes

1. Centring long paragraphs. Ragged left edges are tiring to read. Centre headings only.

2. Line height with units. line-height: 20px doesn't scale when the font size changes. Use a plain number such as 1.6.

3. Removing link underlines with no other clue. Visitors can't tell what's clickable.

4. Typing in capitals. Write text normally and use text-transform: uppercase. Screen readers may spell out real capitals letter by letter.


Practice Questions

  1. Which property centres text?
  2. Write a comfortable line height for paragraphs.
  3. How do you make text appear in capitals without retyping it?
  4. Remove the underline from all links.
  5. What does letter-spacing: 3px do?
  6. Why is line-height: 1.6 better than line-height: 24px?

Practice Answers

  1. text-align: center;
  2. p { line-height: 1.6; }
  3. text-transform: uppercase;
  4. a { text-decoration: none; }
  5. It adds 3px of space between letters.
  6. A plain number scales with the font size, so it stays right if the text gets bigger or smaller.

Key Takeaways

  • text-align for alignment; keep body text left-aligned.
  • line-height: 1.5–1.7 makes paragraphs comfortable.
  • text-transform, text-decoration, letter-spacing and text-indent fine-tune text.
  • Links should always look clickable.