An Intro to the CSS text-decoration Property
Description
Example
With the following rules applied, unvisited anchor links are bold, but have no underline, visited links have a line through them, and links in the hover or focus state have a line above and below them:a:link {
font-weight: bold;
text-decoration: none;
}
a:visited {
font-weight: bold;
text-decoration: line-through;
}
a:hover, a:focus {
text-decoration: underline overline;
}
Value
- line-through – This value draws a horizontal line through the text.
- none – This value produces no text decoration (although it doesn’t undo a decoration that’s set on an ancestor element).
- overline – This value draws a horizontal line above the text.
- underline – This value draws a horizontal line below the text.
Frequently Asked Questions about CSS Text Decoration
What is the difference between ‘text-decoration-line’, ‘text-decoration-color’, and ‘text-decoration-style’ in CSS?
In CSS, ‘text-decoration-line’ is used to specify the type of text decoration to be added to an element. It can take values like ‘underline’, ‘overline’, ‘line-through’, and ‘none’.
On the other hand, ‘text-decoration-color’ is used to specify the color of the text decoration. It can take any valid color value.
Lastly, ‘text-decoration-style’ is used to specify the style of the line in a text decoration. It can take values like ‘solid’, ‘double’, ‘dotted’, ‘dashed’, and ‘wavy’.
How can I remove text decoration from a link in CSS?
To remove text decoration from a link, you can use the ‘text-decoration’ property and set its value to ‘none’. Here’s an example:a {
text-decoration: none;
}
This will remove the underline that is typically displayed for links.
Can I apply multiple text decorations to a single element?
Yes, you can apply multiple text decorations to a single element by using the ‘text-decoration-line’ property. You can specify multiple values for this property, separated by spaces. For example:p {
text-decoration-line: underline overline;
}
This will apply both an underline and an overline to the paragraph text.
How can I change the style of an underline in CSS?
You can change the style of an underline in CSS using the ‘text-decoration-style’ property. This property can take values like ‘solid’, ‘double’, ‘dotted’, ‘dashed’, and ‘wavy’. For example:p {
text-decoration-line: underline;
text-decoration-style: wavy;
}
This will apply a wavy underline to the paragraph text.
How can I apply text decoration to only a part of the text?
To apply text decoration to only a part of the text, you can use the ‘span’ element to target the specific part of the text. For example:This is a <span class="underline">underlined</span> text.
.underline {
text-decoration: underline;
}
This will apply an underline to only the word “underlined”.
How can I make a dashed underline in CSS?
To make a dashed underline in CSS, you can use the ‘text-decoration-style’ property and set its value to ‘dashed’. Here’s an example:p {
text-decoration-line: underline;
text-decoration-style: dashed;
}
This will apply a dashed underline to the paragraph text.
How can I change the color of an underline in CSS?
To change the color of an underline in CSS, you can use the ‘text-decoration-color’ property. This property can take any valid color value. For example:p {
text-decoration-line: underline;
text-decoration-color: red;
}
This will apply a red underline to the paragraph text.
Can I use the ‘text-decoration’ shorthand property to specify all text decoration properties at once?
Yes, you can use the ‘text-decoration’ shorthand property to specify the ‘text-decoration-line’, ‘text-decoration-color’, and ‘text-decoration-style’ properties at once. For example:p {
text-decoration: underline red wavy;
}
This will apply a red, wavy underline to the paragraph text.
How can I apply a line-through decoration to text in CSS?
To apply a line-through decoration to text in CSS, you can use the ‘text-decoration-line’ property and set its value to ‘line-through’. Here’s an example:p {
text-decoration-line: line-through;
}
This will apply a line-through decoration to the paragraph text.
How can I remove all text decorations from an element in CSS?
To remove all text decorations from an element, you can use the ‘text-decoration’ property and set its value to ‘none’. Here’s an example:p {
text-decoration: none;
}
This will remove all text decorations from the paragraph text.
Adam is SitePoint's head of newsletters, who mainly writes Versioning, a daily newsletter covering everything new and interesting in the world of web development. He has a beard and will talk to you about beer and Star Wars, if you let him.

Published in
·Design·Design & UX·Illustration·Resources·Review·Software·Typography·UI Design·June 30, 2016