Open In App

CSS text-decoration Property

Last Updated : 28 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In CSS, the text-decoration property is used to control the decoration of text, such as underlines, overlines, line-throughs, and blink effects. This property accepts values like none, underline, overline, and line-through, and inherits to style text decorations accordingly. Understanding the text-decoration property and its shorthand variations allows web developers to enhance the visual presentation of text effectively. This article explores the syntax, use cases, and browser support for the text-decoration property in CSS.


Understanding the text-decoration Property

The text-decoration property in CSS is a shorthand property used to set the decoration of text in one declaration. It combines the text-decoration-line, text-decoration-style, text-decoration-color, and text-decoration-thickness properties.

Syntax:

text-decoration: line style color | initial | inherit;
/* for example
text-decoration: underline dashed green;
*/

CSS text-decoration shorthand property for:

CSS text-decoration Property Examples:

Example 1: Here is the 3 value representation of CSS text-decoration Property.

HTML
<!DOCTYPE html>
<html>
<head>
    <title>Text Decoration Example</title>
    <style>
        h2{
            text-decoration: underline dashed green;
        }
    </style>
</head>
<body>
    <h2>
        Text Decoration Example
    </h2>
   
</body>
</html>

Output:


text-decoration-multivalue-example

CSS text-decoration Property


Example 2: Here is the single value representation of CSS text-decoration Property.

JavaScript
<!DOCTYPE html>
<html>
    <head>
        <title>Text Decoration Example</title>
        <style>
            h2 {
                text-decoration-line: overline;
                text-decoration-style: solid;
                text-decoration-color: blue;
            }
        </style>
    </head>
    <body>
        <h2>Text Decoration Example</h2>
    </body>
</html>

Output:


text-decoration-single-value-example

CSS Text-Decoration Single value Example


The text-decoration property in CSS is a versatile tool for web developers to control the visual presentation of text. By combining various properties like text-decoration-line, text-decoration-style, text-decoration-color, and text-decoration-thickness, you can create visually appealing text decorations that enhance user experience and site aesthetics. Understanding how to use this property effectively ensures your web content is both stylish and accessible. Stay updated with browser compatibility to maintain a consistent look across different platforms.

Supported Browsers:

The browser supported by value attribute in option tag are listed below:



Next Article

Similar Reads

  翻译: