Back to Blog
JavaScript

CSS Text Decoration: Beyond Underlines - A 2025 Guide

10/24/2025
5 min read
CSS Text Decoration: Beyond Underlines - A 2025 Guide

Stop just underlining links! Master CSS text-decoration with this in-depth guide. Learn line, color, style, thickness, and offset with real-world examples and best practices. Level up your web dev skills.

CSS Text Decoration: Beyond Underlines - A 2025 Guide

CSS Text Decoration: Beyond Underlines - A 2025 Guide

CSS Text Decoration: It's Way More Than Just Underlining Links

Alright, let's talk about one of the most underrated glow-ups in CSS: the text-decoration property.

If you're still thinking, "Oh, that's the thing I use to underline links," my friend, you are in for a treat. The old, one-dimensional text-decoration: underline; has evolved into a full-fledged powerhouse for styling your typography. It’s like going from a basic flip phone to the latest smartphone – the core function is there, but the possibilities are now endless.

We're going to break down everything, from the basics you think you know to the modern, sleek properties that will make your text look absolutely fire. Let's dive in.

What Exactly is CSS Text Decoration? Let's Break it Down

In simple terms, text-decoration is the CSS property you use to add decorative lines to your text. Historically, these lines could be:

  • Underlines: The classic line below the text (like for links).

  • Overlines: A line above the text (less common, but has its uses).

  • Line-through: A line cutting through the text (perfect for showing deleted prices in an e-commerce store).

For the longest time, that was pretty much it. You had very little control over the color, style, or thickness of these lines. It was a take-it-or-leave-it situation. But thanks to modern CSS, we now have a whole set of sub-properties that give us surgical control.

The Old Way vs. The New, Cool Way

The Old Shorthand:
You'd just write a single line.

css

.old-school {
  text-decoration: underline;
}

The Modern, Expanded Family:
Now, we can break it down into its components, giving us way more control.

css

.modern {
  text-decoration-line: underline; /* What line? */
  text-decoration-color: #ff4d4d; /* What color? */
  text-decoration-style: wavy; /* What style? */
  text-decoration-thickness: 2px; /* How thick? */
}

And the best part? You can still use the shorthand, which is now super powerful:

css

.modern-shorthand {
  /* line | style | color | thickness */
  text-decoration: underline wavy #ff4d4d 2px;
}

The Text-Decoration Dream Team: A Deep Dive

Let's get to know each member of this new squad.

1. text-decoration-line - The "What"

This is the foundation. It decides if and what type of line you want.

  • none: Removes any decoration (the default for most text, and crucial for link styling).

  • underline: The GOAT. A line beneath the text.

  • overline: A line above the text. It can give a cool, retro or futuristic vibe if used sparingly.

  • line-through: Your go-to for strike-through text.

Example:

css

.underline { text-decoration-line: underline; }
.overline { text-decoration-line: overline; }
.line-through { text-decoration-line: line-through; }

2. text-decoration-style - The "Vibe"

This is where it gets fun. This property defines the appearance of the line.

  • solid: A single, solid line (the default).

  • double: Two solid lines. Great for a more emphatic underline.

  • dotted: A dotted line. Feels modern and clean.

  • dashed: A dashed line. Perfect for informal or "editable" feels.

  • wavy: A wavy, squiggly line. Awesome for highlighting errors, special notes, or just adding some playful energy.

Example:

css

.double { text-decoration-style: double; }
.dotted { text-decoration-style: dotted; }
.wavy { text-decoration-style: wavy; }

3. text-decoration-color - The "Pop"

This one's simple but game-changing. It sets the color of the decoration line. Before this, the line would always be the same color as the text itself. Now? You can have a blue link with a red wavy underline if you want.

Example:

css

.fancy-link {
  text-decoration: underline;
  text-decoration-color: #4ade80; /* A nice green */
  color: #3b82f6; /* While the text is blue */
}

4. text-decoration-thickness - The "Weight"

This property controls the thickness of the decoration line. You can use absolute units like px or relative units like em. Using em is often a better practice because it scales relative to the font size.

Example:

css

.thick-underline {
  text-decoration: underline;
  text-decoration-thickness: 3px;
}
.better-underline {
  text-decoration: underline;
  text-decoration-thickness: 0.1em; /* Scales with font size */
}

5. text-underline-offset - The "Personal Space"

This might be my favorite. text-underline-offset lets you control the distance between the text and its underline. No more cramped underlines! You can use px, em, or even auto.

Example:

css

.spacious-link {
  text-decoration: underline;
  text-underline-offset: 4px; /* Pushes the underline down */
}

Real-World Use Cases: Let's Get Practical

Enough theory. How do we use this in the real world to make our designs pop?

1. Styling Beautiful, Accessible Links

The days of boring blue underlines are over. Let's create a link style that's both beautiful and clear.

css

.premium-link {
  color: #1e40af; /* A deep blue */
  text-decoration: none; /* Remove the default */
  /* Create a custom, subtle underline */
  text-decoration-line: underline;
  text-decoration-color: #93c5fd; /* A light blue */
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  transition: all 0.2s ease-in-out; /* Add a smooth hover effect */
}

.premium-link:hover {
  color: #dc2626; /* Change text color on hover */
  text-decoration-color: #dc2626; /* Match the underline color */
  text-decoration-thickness: 3px;
}

2. Highlighting Errors with Wavy Underlines

Instead of just turning a input field red, you can add a wavy underline to the label or the text itself for an extra clear error message.

css

.error-text {
  color: #b91c1c;
  text-decoration: wavy underline #b91c1c 1px;
}

3. Creating a "Sold Out" or "On Sale" Effect

For e-commerce, use a double line-through for the original price and a wavy underline for a "limited time offer" message.

css

.original-price {
  text-decoration: double line-through #9ca3af;
}
.sale-banner {
  text-decoration: wavy overline #10b981;
}

Best Practices & Things to Keep in Mind

  1. Accessibility is Key: While you can make underlines any color, ensure there is sufficient contrast between the underline and the background. Also, don't rely solely on color or decoration to convey meaning (e.g., for errors).

  2. Don't Go Overboard: Wavy lines, double overlines, and bold colors are great, but using them all at once can make your design look messy and unprofessional. Subtlety is your friend.

  3. Use text-underline-offset for Better Readability: Especially for fonts with long descenders (like 'g', 'j', 'p', 'q', 'y'), a default underline can look cluttered. A small offset of 1px or 0.05em can dramatically improve legibility.

  4. Check Browser Support: The modern properties (thickness, offset) are well-supported in all modern browsers, but it's always good to have a fallback. Using the shorthand is a safe bet.

Mastering these CSS details is what separates hobbyists from professionals. If you're looking to build a rock-solid foundation in modern web development, our Full Stack Development course at CoderCrafter dives deep into CSS, JavaScript, and the frameworks that power the modern web. To learn professional software development courses such as Python Programming, Full Stack Development, and MERN Stack, visit and enroll today at codercrafter.in.

FAQs (Frequently Asked Questions)

Q1: Can I use multiple lines on the same text?
Yes! You can combine them in the text-decoration-line property. For example, text-decoration-line: underline overline; will give you both.

Q2: How is text-decoration different from border-bottom?
Great question! border-bottom creates a box-model border that spans the entire width of the element (unless it's an inline element like a link). text-decoration follows the shape of the text itself, breaking between letters and words, which is generally the desired behavior for underlining text.

Q3: Why is my text-underline-offset not working?
The most common reason is that you don't have an underline defined. Make sure text-decoration-line: underline; is set, either directly or via the shorthand.

Q4: Can I animate these properties?
You can animate text-decoration-color, text-underline-offset, and text-decoration-thickness! This is perfect for creating smooth, interactive hover effects on links.

Conclusion: Stop Sleeping on Text Decoration!

The humble text-decoration property has truly leveled up. It's no longer just a blunt instrument for underlining links. It's a precise, creative tool that gives you the power to enhance your typography, improve user experience, and add those subtle touches that make a design feel polished and modern.

So, the next time you're styling a link, a heading, or any piece of text, don't just settle for the default. Experiment with a wavy line, adjust the offset for better readability, or add a pop of color. These small details are what will make your websites stand out.

Related Articles

Call UsWhatsApp