Skip to main content

Beginner-Friendly Topic

Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!

Lesson 3 of 10

Text Styling & Effects

Beyond basic font properties, CSS offers powerful text styling options - alignment, decoration, transformation, indentation, and wrapping. These properties control how text displays, wraps, and interacts with its container.

15 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Text Properties

  • text-align - left, center, right, justify. Controls horizontal text alignment within its container
  • text-decoration - none (remove underlines), underline, line-through, overline. Style with text-decoration: underline wavy #E44D26
  • text-transform - uppercase, lowercase, capitalize. UPPERCASE for buttons and labels
  • text-indent - First line indent: text-indent: 2em. Used for traditional paragraph styling
  • white-space - nowrap (prevent wrapping), pre (preserve formatting), pre-wrap (preserve but wrap)
  • word-break - break-all (break anywhere), keep-all. Prevents long URLs/words from overflowing containers
  • text-overflow - ellipsis (...) for truncated text. Requires overflow: hidden and white-space: nowrap

Text Effects Code

Text Effects Code
/* Text truncation with ellipsis */
.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
}

/* Multi-line truncation (modern) */
.clamp-3-lines {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Decorative underline */
.fancy-link {
  text-decoration: none;
  background-image: linear-gradient(#E44D26, #E44D26);
  background-position: 0 100%;
  background-repeat: no-repeat;
  background-size: 0% 2px;
  transition: background-size 0.3s ease;
}
.fancy-link:hover {
  background-size: 100% 2px;
}

/* Uppercase label */
.label {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.75rem;
  font-weight: 700;
}

Tip

Create a reusable .truncate utility class that applies all three properties - white-space: nowrap; overflow: hidden; text-overflow: ellipsis - so you can truncate any text with a single class. This is standard practice in design systems.

Diagram
Loading diagramโ€ฆ

CSS text properties provide precise control over alignment, decoration, casing, and truncation

Common Mistake

text-overflow: ellipsis alone does nothing without overflow: hidden and white-space: nowrap. All three must be present simultaneously. Also, the container needs a defined width or max-width - without it, the text has unlimited space and will never truncate.

Practice Task

Create a card component with: (1) a title that truncates with ellipsis after 200px, (2) a description that clamps to 3 lines using -webkit-line-clamp: 3, (3) a .label class with text-transform: uppercase and letter-spacing: 0.1em for a professional badge appearance.

Quick Quiz

Key Takeaways

  • Beyond basic font properties, CSS offers powerful text styling options - alignment, decoration, transformation, indentation, and wrapping.
  • text-align - left, center, right, justify. Controls horizontal text alignment within its container
  • text-decoration - none (remove underlines), underline, line-through, overline. Style with text-decoration: underline wavy #E44D26
  • text-transform - uppercase, lowercase, capitalize. UPPERCASE for buttons and labels

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/10 done