Text decoration lets you add lines or styles to text to make it stand out or look different.
Text decoration in CSS
Start learning this pattern below
Jump into concepts and practice - no test required
selector {
text-decoration: value;
}The value can be underline, overline, line-through, none, or a combination.
You can also control the color and style of the decoration with extra properties.
p {
text-decoration: underline;
}a {
text-decoration: none;
}h1 {
text-decoration: overline;
}span {
text-decoration: line-through;
}This page shows different text decorations: underlined link, link without underline, struck-through text, and overlined text.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Text Decoration Example</title> <style> body { font-family: Arial, sans-serif; padding: 1rem; } a { text-decoration: underline; color: blue; } a.no-underline { text-decoration: none; color: red; } .strike { text-decoration: line-through; color: gray; } .overline { text-decoration: overline; color: green; } </style> </head> <body> <p>This is a <a href="#">normal link</a> with underline.</p> <p>This is a <a href="#" class="no-underline">link without underline</a>.</p> <p class="strike">This text is struck through.</p> <p class="overline">This text has an overline.</p> </body> </html>
Text decoration helps users understand meaning or importance of text visually.
Use text-decoration: none; carefully to avoid confusing users about links.
You can combine decorations like underline overline for multiple lines.
Text decoration adds lines like underline, overline, or line-through to text.
It is useful for links, emphasis, or showing deleted text.
You can control style and color for better design and accessibility.
Practice
Solution
Step 1: Identify the property for text lines
The propertytext-decorationcontrols lines like underline, overline, and line-through on text.Step 2: Confirm the underline effect
Usingtext-decoration: underline;adds an underline to the text.Final Answer:
text-decoration -> Option DQuick Check:
Underline = text-decoration [OK]
- Confusing font-style with underline
- Using text-transform which changes case
- Using line-height which controls spacing
Solution
Step 1: Recall valid text-decoration values
The valid values fortext-decorationincludeunderline,overline, andline-through.Step 2: Match the line-through effect
The correct value to cross out text isline-through. Other options likestrikeorcrossedare invalid.Final Answer:
text-decoration: line-through; -> Option BQuick Check:
Line-through = line-through [OK]
- Using invalid values like strike or crossed
- Confusing overline with line-through
- Missing the colon or semicolon in syntax
p { text-decoration: underline overline; }Solution
Step 1: Understand multiple values in text-decoration
Thetext-decorationproperty can accept multiple values separated by spaces to combine effects.Step 2: Apply underline and overline together
Usingunderline overlineapplies both lines above and below the text simultaneously.Final Answer:
The paragraph text will have both an underline and an overline. -> Option CQuick Check:
Multiple decorations combine = both lines [OK]
- Assuming only the first value applies
- Thinking values override each other
- Confusing overline with underline
h1 { text-decoration: underlined; }Solution
Step 1: Check valid values for text-decoration
Valid values includeunderline,overline,line-through, but notunderlined.Step 2: Confirm property and syntax correctness
The propertytext-decorationis correct and semicolon is present. The selectorh1is valid.Final Answer:
The value 'underlined' is invalid for text-decoration. -> Option AQuick Check:
Valid values only = underline, overline, line-through [OK]
- Adding 'd' to underline value
- Confusing property names
- Ignoring semicolon errors
Solution
Step 1: Set no decoration normally
Usetext-decoration: none;on the link to remove underline by default.Step 2: Add red underline on hover
Ona:hover, addtext-decoration: underline;and settext-decoration-color: red;to color the underline red.Final Answer:
a { text-decoration: none; } a:hover { text-decoration: underline; text-decoration-color: red; } -> Option AQuick Check:
None normally + red underline on hover = a { text-decoration: none; } a:hover { text-decoration: underline; text-decoration-color: red; } [OK]
- Setting underline always, not only on hover
- Using text-decoration-color without underline
- Reversing hover and normal styles
