CSS Text Decoration

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered

Overview

The text-decoration in CSS property applies different types of decorations to the text to enhance the appearance and make it more appealing to the users. Being a shorthand for multiple CSS properties, text decoration in CSS makes it easier, to combine more than one text-decoration property.

For instance, it can set values for many parameters like text-decoration-line(required), text-decoration-color, text-decoration-thickness, and text-decoration-style.

types-of-text-decoration-property-in-css Here, we apply an aqua-colored dotted underline of 5px to our text.

The inline content can be beautified using text-decoration lines (like underline, overline, line-through, or a combination of them) and changing their color, thickness, and styles (dotted, double-lined, etc.).

Working on Text Decoration in CSS

Text decoration in CSS can be applied to all HTML elements to enhance the appearance of inline elements, according to the developer's choice. It can be used as inline CSS, External CSS, or Internal CSS.

Syntax :

  • Line sets the type of line needed for the text, if it will be underlined, overlined, or struck-through.
  • Color defines the color of the decoration line.
  • Style refers to the style of the decoration line(wavy, dotted, solid, dashed, etc.).
  • Thickness sets values for the thickness of the stroke.

text-decoration-line

The text-decoration-line CSS property refers to the decorative line applied to text in an element. The property can be set as none or one or more space-separated values.

Example :

text-decoration-line-example

Syntax :

Values :

ValueFunctionality
noneThe default value is none. It refers to no text decoration.
underlineUnderline defines that text has a decorative line under it.
overlineOverline defines that text has a decorative line above it.
line-throughline-through refers to the text having a decorative line going through it (struck through).
blinkBlink defines that the text has a flashing or blinking effect (on and off).

Code :

Output :

output-of-text-decoration-line-example-code

text-decoration-color

The text-decoration-color in the CSS property refers to the color of the decorative line applied to text in an element.

Example :

example-of-text-decoration-color

Syntax :

Values :

The color values can be specified in various ways:

Value TypeFunctionality
Color NameValues are assigned with the help of color names.
RGBRGB refers to Red, Green, and Blue, and the value is set in terms of the values (ranging from 0 to 255) of Red, Green, and Blue, respectively.
HSLHSL refers to Hue, Saturation, and Lightness and defines the color's exact shade.
HexadecimalColors are defined by a # followed by a 6-digit representation.

Refer to CSS Color - Scaler Topics to know about CSS colors.

Code :

Output :

output-of-text-decoration-color-example-code

text-decoration-style

The text-decoration-style in CSS property refers to the style or type of the decorative line applied on text in an element.

Example :

example-of-text-decoration-style

Syntax :

Values :

ValueFunctionality
doubleDouble defines that a double line will be created as a decoration line.
solidSolid defines a solid style.
dashedDashed defines that the decoration line will be dashed.
dottedDotted defines a dotted style for the decoration line.
wavyWaved defines a wavy style.
initialInitial is the default value.
inheritInherit defines that the parent element inherits the value.

Code:

Output :

output-of-text-decoration-style

text-decoration-thickness

The text-decoration-thickness in CSS property refers to the thickness of the decorative line applied on text in an element.

Example :

example-of-text-decoration-thickness

Syntax :

Values :

ValueFunctionality
autoThis is the default value. Auto defines that the browser will set value automatically.
form-fontUses value set in the form-font file. If no such value is assigned works as auto.
lengthDefines the thickness of the decoration line applied to text as a length.
percentageDefines the thickness of the decoration line applied to text as a percentage of 1em of the current font.

Code :

Output :

output-of-text-decoration-thickness

Shorthand Property

The text-decoration property in CSS is a shorthand property for multiple parent properties, which are :

  • text-decoration-line
    
  • text-decoration-style
    
  • text-decoration-color
    
  • text-decoration-thickness
    
    Writing all these properties separately becomes tedious and makes the code lengthy. So to improve the legibility of the code, the property text-decoration is short-handed as it covers all four properties.

Code :

Output :

shorthend-property-for-text-decoration

Demonstration of text-decoration Values

A quick overview of the values used for text decoration in CSS :

  • Values for the line : line-value-of-text-decoration

  • Values for color : color-value-of-text-decoration

  • Values for style : style-value-of-text-decoration

  • Values for thickness : thickness-value-of-text-decoration

Browser Compatibility

The longhand form of text-decoration property in css works fine for all browsers. However, the shorthand form is not compatible with browsers like Internet Explorer.

Conclusion

  • Text-decoration-property in CSS is used to apply decoration lines to text.
  • The appearance of the lines can be changed based on their position, color, style, and thickness.
  • Line refers to the type of line needed for the text or where the line is to be positioned. It determines if it will be underlined, overlined, or struck through. A single piece of text can have multiple decoration lines.
  • Color refers to the color of the decoration line.
  • Style refers to how the line will look, whether wavy, dotted, solid or dashed.
  • Thickness refers to the thickness of the stroke of the decoration line.

The related properties of text-decoration property are :

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