0
0
CSSmarkup~15 mins

Text decoration in CSS - Deep Dive

Choose your learning style9 modes available
Overview - Text decoration
What is it?
Text decoration in CSS is a way to add visual styles like lines or effects to text on a webpage. It lets you underline, overline, or strike through words, or add color and style to these lines. This helps make text clearer, more attractive, or to show special meaning like links or deleted content. It works by applying simple properties to text elements in your HTML.
Why it matters
Without text decoration, web pages would look plain and less readable. Important cues like links being underlined or text being crossed out would be missing, making it harder for users to understand the page quickly. Text decoration improves user experience by guiding attention and adding meaning without extra words. It also helps with accessibility by visually distinguishing text types.
Where it fits
Before learning text decoration, you should know basic CSS syntax and how to select HTML elements. After mastering text decoration, you can explore more advanced CSS styling like fonts, shadows, and animations to create rich text effects.
Mental Model
Core Idea
Text decoration is like adding simple visual marks on text to highlight or change its meaning without changing the text itself.
Think of it like...
Imagine writing a note on paper and using a highlighter, underlining, or crossing out words to show importance or correction. Text decoration does the same on web text.
Text Element
  │
  ├─ Text Decoration Line (underline, overline, line-through)
  ├─ Text Decoration Style (solid, dotted, dashed, wavy)
  ├─ Text Decoration Color
  └─ Text Decoration Thickness

Example:
┌─────────────────────────────┐
│ Hello, world!               │
│ └─ underline, solid, red    │
└─────────────────────────────┘
Build-Up - 7 Steps
1
FoundationBasic text-decoration property
🤔
Concept: Learn the main CSS property that adds lines to text.
The CSS property 'text-decoration' lets you add lines like underline, overline, or line-through to text. For example, 'text-decoration: underline;' draws a line under the text. You can apply it to any text element in HTML using CSS selectors.
Result
Text on the webpage appears with a line under it.
Understanding the basic property shows how simple it is to add meaning or style to text with just one CSS rule.
2
FoundationMultiple decoration lines
🤔
Concept: You can combine different lines on the same text.
Using 'text-decoration-line', you can specify multiple lines like 'underline overline'. For example: 'text-decoration-line: underline overline;' draws lines both above and below the text. This property separates the line type from other decoration styles.
Result
Text shows lines both above and below it simultaneously.
Knowing you can combine lines helps create richer text styles beyond just underlining.
3
IntermediateCustomizing line style and color
🤔Before reading on: do you think text-decoration lines can only be solid and black? Commit to your answer.
Concept: You can change how the decoration line looks and its color.
CSS properties 'text-decoration-style' and 'text-decoration-color' let you change the line's appearance. Styles include solid, dotted, dashed, double, and wavy. Color can be any valid CSS color. For example: p { text-decoration-line: underline; text-decoration-style: wavy; text-decoration-color: red; } This creates a red wavy underline.
Result
Text has a red wavy underline instead of a plain solid black line.
Customizing style and color makes text decoration a powerful tool for matching design and conveying tone.
4
IntermediateUsing text-decoration-thickness
🤔Before reading on: do you think the thickness of text decoration lines can be changed? Commit to yes or no.
Concept: You can control how thick or thin the decoration line is.
The 'text-decoration-thickness' property adjusts the thickness of the decoration line. It accepts length units like '2px' or keywords like 'auto' or 'from-font'. For example: h1 { text-decoration-line: underline; text-decoration-thickness: 3px; } This makes the underline thicker than default.
Result
The underline under the heading is visibly thicker.
Adjusting thickness helps emphasize or soften the decoration, improving visual hierarchy.
5
IntermediateShorthand text-decoration property
🤔
Concept: Combine line, style, color, and thickness in one property.
The 'text-decoration' shorthand lets you write all decoration settings in one line. For example: span { text-decoration: underline dotted blue 2px; } This means underline line, dotted style, blue color, and 2px thickness all at once.
Result
Text has a blue dotted underline with thickness 2px.
Using shorthand simplifies CSS and keeps code clean and readable.
6
AdvancedText decoration and accessibility
🤔Before reading on: do you think text decoration affects screen readers or only visual users? Commit to your answer.
Concept: Text decoration is purely visual but impacts how users perceive content meaning.
Screen readers ignore text decoration because it doesn't change the text content. However, visual cues like underlines for links help users understand what is clickable. Designers must ensure decoration matches meaning and not rely solely on color or decoration for important info, to support users with visual impairments.
Result
Webpages are more accessible and usable for all users.
Knowing decoration is visual only guides better inclusive design practices.
7
ExpertBrowser rendering and performance quirks
🤔Before reading on: do you think all browsers render text-decoration exactly the same? Commit to yes or no.
Concept: Different browsers handle decoration lines with subtle differences affecting appearance and performance.
Browsers may vary in how they draw wavy or double lines, line thickness limits, or how decoration interacts with text transformations and animations. Some older browsers do not support all styles or thickness control. Understanding these quirks helps developers write fallback styles and test across devices for consistent user experience.
Result
Text decoration looks consistent and performs well on all browsers.
Awareness of browser differences prevents unexpected visual bugs and improves cross-platform reliability.
Under the Hood
Text decoration works by the browser drawing extra lines or effects on top of the text glyphs after layout is calculated. It does not change the text content or font but overlays visual marks based on CSS rules. The rendering engine calculates line position relative to the text baseline and applies styles like color, thickness, and pattern. This separation keeps text selectable and accessible while adding decoration.
Why designed this way?
Separating decoration from text content allows styling without altering meaning or structure. Early web needed simple ways to show links and emphasis. The design evolved to support more styles and control while maintaining accessibility and performance. Alternatives like embedding decoration in fonts were less flexible and harder to update.
┌─────────────────────────────┐
│ Text Content (characters)    │
├─────────────────────────────┤
│ CSS Text Decoration Rules   │
│  ├─ Line type (underline)    │
│  ├─ Style (dotted, wavy)    │
│  ├─ Color                   │
│  └─ Thickness               │
├─────────────────────────────┤
│ Browser Rendering Engine    │
│  └─ Draws decoration lines  │
└─────────────────────────────┘
Myth Busters - 4 Common Misconceptions
Quick: Does 'text-decoration' change the actual text content? Commit to yes or no.
Common Belief:Text decoration changes the text itself, like adding characters or modifying letters.
Tap to reveal reality
Reality:Text decoration only adds visual lines or effects on top of the text; it does not alter the text content or characters.
Why it matters:Thinking decoration changes text can lead to confusion about accessibility and text selection behavior.
Quick: Can you style text-decoration lines with any CSS color? Commit to yes or no.
Common Belief:Text decoration lines are always black or inherit the text color and cannot be changed independently.
Tap to reveal reality
Reality:You can set 'text-decoration-color' to any valid CSS color, independent of the text color.
Why it matters:Knowing this allows designers to create more expressive and clear text styles.
Quick: Do all browsers support 'text-decoration-thickness'? Commit to yes or no.
Common Belief:All browsers fully support changing the thickness of text decoration lines.
Tap to reveal reality
Reality:Support for 'text-decoration-thickness' varies; some older browsers ignore it or have limited support.
Why it matters:Assuming full support can cause inconsistent appearance and unexpected bugs on some devices.
Quick: Does adding multiple lines with 'text-decoration-line' stack lines visually? Commit to yes or no.
Common Belief:Multiple lines like underline and overline stack and overlap perfectly without spacing.
Tap to reveal reality
Reality:Browsers space multiple decoration lines apart to avoid overlap, so they appear as separate lines above and below text.
Why it matters:Misunderstanding this can cause layout surprises when combining multiple lines.
Expert Zone
1
Some browsers optimize text-decoration rendering by combining lines with font metrics, which can cause subtle shifts in line position when font or size changes.
2
Using 'text-decoration-skip-ink' controls whether decoration lines break around descenders (like 'g' or 'y'), improving readability but not supported everywhere.
3
Animations on text-decoration properties are limited; animating thickness or style often requires workarounds like using box shadows or pseudo-elements.
When NOT to use
Avoid relying solely on text decoration to convey critical information, especially for accessibility. Use semantic HTML elements like for deletions or for links combined with decoration. For complex text effects or animations, consider SVG or canvas-based solutions instead.
Root cause:Confusing visual style with semantic meaning leads to accessibility and usability issues.
#2Setting text-decoration color without specifying line type.
Wrong approach:p { text-decoration-color: red; }
Correct approach:p { text-decoration-line: underline; text-decoration-color: red; }
Root cause:Forgetting that color applies only if a decoration line is set causes no visible effect.
#3Overusing multiple decoration lines causing clutter.
Wrong approach:h2 { text-decoration-line: underline overline line-through; }
Correct approach:h2 { text-decoration-line: underline; }
Root cause:Trying to combine too many lines reduces readability and confuses users.
Key Takeaways
Text decoration adds visual lines like underline, overline, and line-through to text without changing the text itself.
You can customize decoration lines with style, color, and thickness for richer design control.
Text decoration is purely visual and does not affect screen readers or text content meaning.
Using semantic HTML elements alongside decoration ensures accessibility and proper meaning.
Browser support varies for some decoration features, so testing and fallbacks are important.