On this page10 sections
Lecture 009: Styling Text
| Category | 3: Text, Fonts & Content |
| Lecture | 009 of 057 |
| Estimated video length | 12 min |
| Target | CSS3 · any modern browser |
| Level | Beginner |
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-heightandletter-spacing - Change case with
text-transformand underlines withtext-decoration - Style links, and add
text-shadow
1. Alignment
Example
<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
<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
<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>4. Styling Links
Links have states, which you'll study in Lecture 020. The most common look:
Example
<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
<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
- Which property centres text?
- Write a comfortable line height for paragraphs.
- How do you make text appear in capitals without retyping it?
- Remove the underline from all links.
- What does
letter-spacing: 3pxdo? - Why is
line-height: 1.6better thanline-height: 24px?
Practice Answers
text-align: center;p { line-height: 1.6; }text-transform: uppercase;a { text-decoration: none; }- It adds 3px of space between letters.
- A plain number scales with the font size, so it stays right if the text gets bigger or smaller.
Key Takeaways
text-alignfor alignment; keep body text left-aligned.line-height: 1.5–1.7makes paragraphs comfortable.text-transform,text-decoration,letter-spacingandtext-indentfine-tune text.- Links should always look clickable.