Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS text-decoration Property

Posted in CSS Tutorial
Updated on Oct 13, 2024
By Mari Selvan
👁️ 21 - Views
⏳ 4 mins
💬 1 Comment
CSS text-decoration Property

Photo Credit to CodeToFun

🙋 Introduction

The text-decoration property in CSS is used to set the text formatting to underline, overline, line-through, or a combination of these styles.

It is a shorthand property for several sub-properties that allow you to control the appearance of decorative lines on text.

💡 Syntax

The syntax for the text-decoration property is as follows:

Syntax
Copied
Copy To Clipboard
element {
  text-decoration: value;
}

The value can be a combination of keywords and other values.

🎛️ Default Value

The default value of the text-decoration property is none, which means no decoration is applied to the text.

🏠 Property Values

ValueDescription
noneRemoves any text decoration.
underlineAdds an underline beneath the text.
overlineAdds a line above the text.
line-throughAdds a line through the text.
blinkCauses the text to blink (Note: Blinking text is not widely supported and can be distracting).
text-decoration-colorSpecifies the color of the decoration line.
text-decoration-styleSpecifies the style of the decoration line (solid, double, dotted, dashed, wavy).
text-decoration-thicknessSpecifies the thickness of the decoration line.

📄 Example

In this example, we'll demonstrate different text-decoration values.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS text-decoration Example</title>
  <style>
    .underline {
      text-decoration: underline;
    }
    .overline {
      text-decoration: overline;
    }
    .line-through {
      text-decoration: line-through;
    }
    .custom {
      text-decoration: underline wavy red;
    }
  </style>
</head>
<body>
  <h1>Text Decoration Examples</h1>
  <p class="underline">This text is underlined.</p>
  <p class="overline">This text has an overline.</p>
  <p class="line-through">This text has a line through it.</p>
  <p class="custom">This text has a wavy red underline.</p>
</body>
</html>

🖥️ Browser Compatibility

The text-decoration property is widely supported across all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. The text-decoration-thickness and text-decoration-style sub-properties are also supported in most modern browsers, but it is always a good practice to test your website to ensure compatibility.

🎉 Conclusion

The text-decoration property is a versatile tool for adding emphasis or style to your text.

Whether you need underlines, overlines, or line-throughs, this property offers a range of options to enhance your typography. Experiment with different values and combinations to find the perfect style for your text elements.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy