Aral Code

Text & Content Lesson 10 of 33

CSS Text — Alignment, Decoration, Spacing and Transform

Style text with CSS — align it, underline or remove underlines, change letter case, and adjust line height and letter spacing for easy reading.

Most of a website is text, so how that text is arranged makes a huge difference. In this lesson you'll learn the properties that control text layout: alignment, decoration, letter case, and spacing. (Font family, size and weight are in the next lesson.)

text-align

Aligns text inside its box: left (default for English), right, center, or justify (both edges straight, like a newspaper column).

Example Text alignment
<style>
  p { border: 1px solid #ddd; padding: 8px; font-family: Arial, sans-serif; }
</style>
<p style="text-align: left;">Left: The quick brown fox jumps over the lazy dog near the bamboo fence.</p>
<p style="text-align: center;">Center: The quick brown fox jumps over the lazy dog near the bamboo fence.</p>
<p style="text-align: right;">Right: The quick brown fox jumps over the lazy dog near the bamboo fence.</p>
<p style="text-align: justify;">Justify: The quick brown fox jumps over the lazy dog near the bamboo fence, and keeps running all the way to the barangay hall before sunset.</p>

text-decoration

Adds or removes lines on text: underline, line-through, overline, or none. The most common use is removing the underline from links in menus:

Example Text decoration
<style>
  .old { text-decoration: line-through; color: #888; }
  .new { color: #b4372b; font-weight: bold; }
  nav a { text-decoration: none; margin-right: 12px; }
  .fancy { text-decoration: underline wavy #CE1126; }
</style>
<p>Price: <span class="old">₱499</span> <span class="new">₱299</span></p>
<nav><a href="#">Home</a><a href="#">Shop</a><a href="#">Contact</a></nav>
<p class="fancy">A wavy red underline</p>

You can set the line's style and color too, as in the last example. Modern CSS also has text-underline-offset to move the underline a little lower so it doesn't touch letters like "g" and "y".

text-transform

Changes letter case without changing the HTML: uppercase, lowercase, or capitalize (first letter of each word).

Example Text transform
<p style="text-transform: uppercase;">uppercase: barangay assembly</p>
<p style="text-transform: lowercase;">LOWERCASE: BARANGAY ASSEMBLY</p>
<p style="text-transform: capitalize;">capitalize: barangay assembly</p>

Why not just type capital letters? Because if your design changes later (say, the menu should no longer be all caps), you change one CSS line instead of retyping every word. Screen readers also read normal words more naturally than ALL-CAPS text, which some read letter by letter.

line-height: space between lines

line-height controls the vertical space each line takes. A unitless number like 1.6 means "1.6 times the font size". For body text, 1.5 to 1.7 is the sweet spot for reading comfort.

Example Line height
<style>
  p { font-family: Georgia, serif; font-size: 16px; max-width: 420px; }
</style>
<p style="line-height: 1;"><strong>1.0</strong> — Lines are cramped. Reading a long paragraph like this is tiring because the eye easily jumps to the wrong line.</p>
<p style="line-height: 1.6;"><strong>1.6</strong> — Comfortable. There's enough space between lines, so the eye moves easily from the end of one line to the start of the next.</p>
<p style="line-height: 2.4;"><strong>2.4</strong> — Too loose. The lines feel disconnected, like separate sentences.</p>

letter-spacing and word-spacing

letter-spacing adds space between letters; word-spacing adds space between words. A little letter spacing makes uppercase labels look more polished.

Example Letter spacing
<style>
  .label { text-transform: uppercase; font-size: 13px; font-weight: bold; color: #0f5c4d; font-family: Arial, sans-serif; }
</style>
<p class="label" style="letter-spacing: 0;">Featured lesson</p>
<p class="label" style="letter-spacing: 2px;">Featured lesson</p>

text-indent

Indents the first line of a paragraph, like in printed books and essays:

p { text-indent: 2em; }

Long words and overflow

Very long words or links (like a long Google Drive URL) can stick out of a narrow box on phones. Two helpful properties:

.content { overflow-wrap: break-word; }   /* break long words to fit */

.title {
  white-space: nowrap;        /* keep on one line */
  overflow: hidden;
  text-overflow: ellipsis;    /* show "…" when it doesn't fit */
}
Example Ellipsis for long titles
<style>
  .title { width: 240px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 1px solid #ccc; padding: 6px; }
</style>
<p class="title">Group 3 Final Output — Research on the Effects of Social Media on Grade 10 Students</p>

text-shadow

text-shadow adds a shadow behind text: horizontal offset, vertical offset, blur, and color.

Example Text shadow
<style>
  h1 { font-family: Arial, sans-serif; font-size: 40px; color: #FCD116; text-shadow: 2px 2px 0 #0038A8, 4px 4px 6px rgba(0,0,0,0.3); }
</style>
<h1>MABUHAY!</h1>

Use shadows lightly. A soft shadow can help text stand out on a photo, but heavy shadows on body text make it harder to read.

Quick Quiz

Check what you learned. Walang grade ito, practice lang. 🙂

1. How do you remove the underline from links?
2. What is a comfortable line-height for body text?
3. Which shows "barangay assembly" as "Barangay Assembly"?
4. text-align: center is applied to a div with width: 300px. What happens?

By Sir Reyel · Last updated 2026-12-04