CSS Text
You have sized boxes and controlled overflow. Now shape the words inside. CSS text properties handle alignment, underlines, letter case, spacing between letters, and the height of each line — without changing the font family yet (that comes next).
Everyday text tools
📊 Common text properties
| Property | Everyday job |
|---|---|
text-align |
Aligns text in its line box: left, right, center, justify |
text-decoration |
Adds or removes underline, overline, or line-through |
text-transform |
Changes letter case: uppercase, lowercase, capitalize |
line-height |
Sets the height of each line — key for readable paragraphs |
letter-spacing |
Adjusts space between letters |
Align the text
text-align places text along the horizontal axis of its containing block.
Center a heading
css.hero-title {
text-align: center;
color: #0f172a;
}
Decoration — underline and friends
text-decoration draws lines on text. Links often start underlined; you can remove that with none, or add underline / line-through when the design needs it.
Decoration samples
css.link-quiet {
text-decoration: none;
color: #2563eb;
}
.sale {
text-decoration: line-through;
color: #64748b;
}
.note {
text-decoration: underline;
}
Transform letter case
text-transform changes how letters appear without rewriting the HTML text.
Case transforms
css.label {
text-transform: uppercase;
letter-spacing: 0.06em;
}
.city {
text-transform: capitalize;
}
Line height for readable paragraphs
line-height controls the vertical rhythm of lines. Unitless values like 1.5 scale with the font size and are a calm default for body text.
Comfortable line height
css.article p {
line-height: 1.6;
color: #334155;
}
Letter spacing — a light touch
A little letter-spacing can open a short heading. Keep body paragraphs mostly natural unless the design truly needs it.
Heading with light tracking
css.section-title {
text-align: left;
text-transform: uppercase;
letter-spacing: 0.08em;
line-height: 1.3;
}
Try it yourself
- Center an
h1withtext-align: center. - Remove a link underline with
text-decoration: none, then add a hover underline if you like. - Uppercase a small label with
text-transform: uppercase. - Set paragraph
line-heightto1.6and compare with1.2. - Nudge a heading with a small
letter-spacing— then check it still feels readable.
Common mistakes
- Using
text-align: centerhoping to center a whole block layout (that is a layout job, not only text) - Leaving every link underlined when the design wants quiet links — or removing underlines with no other affordance
- Putting font-family and font-size work here (those belong in the Fonts lesson)
- Huge
letter-spacingon long paragraphs (hard to read) - Confusing text overflow ellipsis tools with these basics (later specialty)
Summary
text-alignaligns text left, right, center, or justifytext-decorationadds or removes underlines and similar linestext-transformchanges letter case without editing HTMLline-heightshapes paragraph readability- Light
letter-spacingcan polish short headings - Fonts come next; keep this lesson on how text sits and reads
🧠 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