🎨 CSS Tutorial: text-decoration

πŸ“Œ Introduction

The text-decoration property in CSS is used to apply text decorations such asunderline, overline, line-through, and more β€” all in a single shorthand property. It allows you to style text links, headings, labels, menu items, and any inline text with one clean, concise declaration. ✨

🎯 Why Use text-decoration?

  • To underline or strike through text effectively ✍️
  • To combine multiple decoration properties in one rule 🎨
  • To create modern link styles πŸ”—
  • To adjust decoration styles, colors, and thickness in shorthand

🧠 What is the text-decoration Shorthand?

The text-decoration property is a shorthand for these individual properties:

  • text-decoration-line
  • text-decoration-style
  • text-decoration-color
  • text-decoration-thickness

Using text-decoration lets you set all of them at once. πŸš€

✨ Syntax

Basic Syntax

text-decoration: line style color thickness;

Note

All values are optional except the line. The order of values does not matter.

🧩 Available text-decoration Values

1. Line Options

  • none
  • underline
  • overline
  • line-through

2. Style Options

  • solid
  • dashed
  • dotted
  • double
  • wavy

3. Color Options

Accepts any valid CSS color: hex, rgb, hsl, named colors, etc.

4. Thickness Options

Accepts lengths (px, em) or percentages.

πŸ”₯ Examples

1. Underline Only

Underline

p {
  text-decoration: underline;
}

2. Strike-through With Color

Line-through with color

.old-price {
  text-decoration: line-through red;
}

3. Fancy Underline Style

Styled underline

.fancy {
  text-decoration: underline wavy #ff5733 3px;
}

4. Overline + Custom Thickness

Overline with thickness

h1 {
  text-decoration: overline solid 2px;
}

5. Full Modern Link Styling

Modern link design

a {
  color: #222;
  text-decoration: underline dotted #0077ff 2px;
  text-underline-offset: 4px;
}

πŸ“Š Comparison Table

Shorthand ValueMeaning
underlineUnderline with default style & color
line-through redStrike-through in red
underline wavy blue 3pxWavy blue underline with thickness
overline double #000Double overline in black

πŸ–ΌοΈ Visual Example

>>β€œSmall details create the big picture β€” even your underlines tell a story.” ✨

πŸŽ‰ Conclusion

The text-decoration property is a powerful shorthand that lets you style text decorations quickly and beautifully. With full control over line, style, color, and thickness, you can create clean, modern, and expressive text styles for your website. Master it and elevate your typography today! πŸš€