Loading...

Text Decoration

Text Decoration in CSS is the art of enhancing the visual appearance of text by adding effects such as underlines, overlines, line-throughs, wavy lines, or adjusting their color, thickness, and style. It is not merely aesthetic—it serves a critical role in guiding user attention and improving content readability. Imagine building a house: the structure represents the semantic HTML, and the text decoration is like decorating rooms, painting walls, and arranging furniture to make the space inviting. In a portfolio website, text decoration can highlight a designer’s name or project titles. On a blog, it can differentiate quotes or hyperlinks. In e-commerce platforms, strikethroughs can indicate discounts, and colorful underlines can call out special deals. On a news site, urgent headlines can feature bold, wavy underlines to capture attention quickly. Even social platforms can use text decoration to distinguish active links or trending tags.
This tutorial will teach you how to use CSS text-decoration properties like text-decoration-line, text-decoration-color, text-decoration-style, and text-decoration-thickness in practical scenarios. You will learn how to combine these properties to create advanced effects, how to make decorations responsive, and how to avoid common mistakes that harm usability. By the end, you will have the ability to “organize your content like a library” where every piece of text is not just informative but also visually expressive and aligned with the website’s brand identity.

Basic Example

css
CSS Code
/* Basic text decoration example for a blog title */
h1 {
text-decoration-line: underline; /* Add an underline to the text */
text-decoration-color: blue; /* Make the underline blue */
text-decoration-style: wavy; /* Make the underline wavy */
}

This code demonstrates a foundational example of text decoration in CSS, aimed at making a main heading (h1) more visually engaging.
The selector h1 targets all level-one headings in the document. The property text-decoration-line: underline applies a simple underline to the text. While beginners often use the shorthand text-decoration: underline, using text-decoration-line allows more granular control, enabling combinations with other advanced properties.
Next, text-decoration-color: blue changes the underline color without affecting the text color. This separation allows for creative designs, such as using brand colors for links or emphasizing certain headings without altering the text’s readability. For instance, a blog could underline post titles in a subtle brand-specific color to unify design and identity.
The property text-decoration-style: wavy changes the line from a default straight style to a wavy one. This is particularly useful in scenarios where attention-grabbing decoration is needed, such as highlighting an urgent announcement on a news site or a playful title on a personal portfolio.
Together, these three properties form the core of advanced text decoration: line type, color, and style. Developers can extend this combination with thickness and offset for precision control. Practically, this allows you to create headings that both capture attention and align with the site’s tone—serious for a news website or playful for a social platform—without introducing additional elements or images.

Practical Example

css
CSS Code
/* Practical e-commerce and portfolio example */
.price-old {
text-decoration-line: line-through; /* Strike through old price */
text-decoration-color: gray; /* Use gray to reduce emphasis */
}
a.highlight-link {
text-decoration-line: underline overline; /* Add both underline and overline */
text-decoration-color: red; /* Highlight offers in red */
text-decoration-thickness: 3px; /* Make the line thicker for visibility */
}

In real-world applications, text decoration is often tied directly to usability and business goals. This example simulates two common use cases: e-commerce pricing and call-to-action links.
The .price-old class applies a line-through to an old price using text-decoration-line: line-through. This immediately communicates that the price is outdated or discounted, which is a standard visual cue in online stores. Using text-decoration-color: gray ensures the line doesn’t overpower the surrounding content, maintaining a clear hierarchy where the new price remains the focus.
The a.highlight-link class is designed for special offers or featured links. text-decoration-line: underline overline combines a bottom and top line to draw attention from multiple directions. Adding text-decoration-color: red provides a strong, action-oriented signal, ideal for sales or limited-time promotions. Finally, text-decoration-thickness: 3px increases the line’s visual weight, making it noticeable even in dense layouts like portfolio galleries or social feeds.
In practical terms, such styling enhances scannability and user engagement. On a social platform, similar decorations can highlight trending hashtags. On a portfolio site, they can emphasize project categories. This combination of properties demonstrates the balance of aesthetics and communication—decoration is not random “eye candy” but a structured visual signal, much like organizing books in a library to guide readers intuitively.

Best practices for text decoration focus on achieving clarity and maintainability without sacrificing performance.
Recommended best practices:

  1. Mobile-first design: Ensure decorations are visible yet not overwhelming on small screens. For example, thick underlines can be scaled down for mobile.
  2. Performance optimization: Avoid overusing complex decorations like thick wavy lines on long text, which can increase rendering overhead.
  3. Maintainable code: Use class-based selectors (e.g., .highlight-link) instead of inline styles to keep code organized and reusable.
  4. Consistent design language: Match decoration color and style to the site’s branding to create a unified experience.
    Common mistakes to avoid:

  5. Over-decoration: Combining multiple line types and colors can make text cluttered and reduce readability.

  6. Specificity conflicts: Overusing !important or deeply nested selectors can make maintenance difficult.
  7. Ignoring responsiveness: Decorations that look great on desktop may overlap text or disappear on mobile.
  8. Browser support issues: Some advanced properties, like text-decoration-thickness, may not fully work in older browsers.
    Debugging tips: Use browser DevTools to inspect which decorations are applied, verify line thickness and color, and test multiple breakpoints. Practically, start with a minimal design, then enhance progressively to balance attention and readability without harming performance.

📊 Quick Reference

Property/Method Description Example
text-decoration-line Defines the type of text decoration underline, overline, line-through
text-decoration-color Changes the decoration line color red, #0000ff
text-decoration-style Defines the line style solid, dotted, wavy
text-decoration-thickness Controls the thickness of the line 2px, 0.1em
text-underline-offset Adjusts the underline distance from text 3px, 0.2em

In summary, mastering text decoration in CSS equips you with the ability to highlight, emphasize, and guide user focus effectively. You learned how to control decoration line type, color, style, and thickness, and how these properties can combine to create clear, expressive text without additional markup.
Text decoration works closely with HTML structure since headings, links, and price labels are the usual candidates. When paired with JavaScript, these effects can become interactive—for example, adding or changing decorations on hover, focus, or click events. This opens the door for subtle animations or responsive cues, improving engagement on blogs, portfolios, and e-commerce sites alike.
Next steps include exploring text-shadow for depth effects, learning about gradient text techniques using background-clip, and combining decorations with CSS animations for dynamic emphasis. Continual experimentation on different site types—news, social, and commercial—will deepen your understanding and prepare you for building polished, professional web interfaces that “decorate the text as beautifully as arranging a well-organized library.”

🧠 Test Your Knowledge

Ready to Start

Test Your Knowledge

Test your understanding of this topic with practical questions.

4
Questions
🎯
70%
To Pass
♾️
Time
🔄
Attempts

📝 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