The text-decoration
property in CSS is a powerful tool for enhancing the visual appearance of text. It allows you to add various decorative lines to your text, such as underlines, overlines, and line-throughs.
The basic syntax for the text-decoration
property is straightforward:
selector {
text-decoration: value;
}
The value
can be one of the following:
none
: Removes any existing decorationunderline
: Adds a line below the textoverline
: Adds a line above the textline-through
: Adds a line through the middle of the textLet's look at some practical examples:
/* Underline text */
.underlined {
text-decoration: underline;
}
/* Remove default underline from links */
a {
text-decoration: none;
}
/* Strikethrough text */
.strikethrough {
text-decoration: line-through;
}
The text-decoration
property can be further customized using additional properties:
text-decoration-color
: Sets the color of the decoration linetext-decoration-style
: Defines the style of the line (solid, wavy, dotted, etc.)text-decoration-thickness
: Specifies the thickness of the linetext-decoration: none;
to remove underlines from links when styling them differentlytext-decoration
with CSS Text Shadow for more visually appealing effectstext-decoration-thickness
to ensure decorations are visible on different backgroundsThe basic text-decoration
property has excellent browser support. However, some of the more advanced properties like text-decoration-thickness
may not be supported in older browsers. Always check browser compatibility when using these features.
To further enhance your text styling skills, explore these related CSS concepts:
By mastering text-decoration
and related properties, you'll be able to create visually appealing and readable text styles in your web projects. Remember to balance aesthetics with readability and accessibility for the best user experience.