32. Text Decoration and Transformation
We can modify the visual appearance of text with lines and capitalization using text-decoration and text-transform.
Text Decoration (text-decoration)
This property is most commonly used to remove or modify the default underline on anchor links (<a>). It is a shorthand for style, line, and color.
Common Usage: Removing Link Underlines
css a { text-decoration: none; /* Removes the default underline / color: blue; / Must manually set the link color */ }
a:hover { text-decoration: underline; /* Adds underline back on hover */ }
Longhand Properties (Modern)
CSS now allows styling the line itself (rarely needed for beginners):
text-decoration-line:underline,overline,line-throughtext-decoration-style:solid,double,wavytext-decoration-color
Text Transformation (text-transform)
This property controls the capitalization of the text content without needing to edit the HTML.
| Value | Description |
|---|---|
uppercase | Converts all text to capital letters. |
lowercase | Converts all text to lowercase letters. |
capitalize | Converts the first letter of every word to uppercase. |
none (default) | Leaves the text as it is. |
css .button { text-transform: uppercase; /* Looks like BUY NOW / letter-spacing: 1px; / Looks better with spacing */ }
.name { text-transform: capitalize; /* Looks like John Smith */ }