Discover how a simple line can make your text clearer and your website friendlier!
Why Text decoration in CSS? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you want to underline some important words in a paragraph by manually adding underscores or dashes around them in your text.
If you try to do this manually, it looks messy, is hard to update, and doesn't work well on different screen sizes or devices.
CSS text decoration lets you easily add underlines, overlines, or line-throughs to text with simple code that works consistently everywhere.
This is _important_ text.
p { text-decoration: underline; }You can style text clearly and beautifully without changing the actual content, making your pages look professional and easy to read.
On a website, links are often underlined automatically using text decoration, so users know what they can click.
Manual text styling is slow and unreliable.
Text decoration in CSS adds lines to text easily and cleanly.
This improves readability and user experience on websites.
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
