Text decoration helps you add styles like underlines to words. It makes important text stand out or look different.
Text decoration and underline in Tailwind
Start learning this pattern below
Jump into concepts and practice - no test required
class="underline" class="line-through" class="no-underline" class="decoration-[color]" class="decoration-[style]"
Use underline to add an underline.
Use line-through to add a line through the text.
<p class="underline">This text is underlined.</p><p class="line-through">This text has a line through it.</p><p class="no-underline">This link has no underline.</p><p class="underline decoration-red-500">Red underline color.</p>This page shows different text decorations using Tailwind CSS. The heading is underlined with a blue line. The first paragraph is simply underlined. The second paragraph has a line through it to show it is crossed out. The link has no underline normally but shows underline when hovered.
<!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> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="p-6 font-sans"> <main> <h1 class="text-2xl font-bold underline decoration-blue-600">Welcome to Tailwind Text Decoration</h1> <p class="mt-4 underline">This paragraph is underlined.</p> <p class="mt-2 line-through text-gray-500">This text is crossed out.</p> <a href="#" class="mt-2 block no-underline text-green-600 hover:underline">This link has no underline by default but underlines on hover.</a> </main> </body> </html>
Tailwind uses utility classes to add or remove text decorations easily.
You can combine underline with decoration-[color] to change underline color.
Use no-underline to remove underlines, especially on links.
Use underline to add underlines to text.
Use line-through to cross out text.
Combine with color classes to style the underline color.
Practice
Solution
Step 1: Understand the purpose of each class
Theunderlineclass adds an underline to text, whileline-throughcrosses out text,no-underlineremoves underline, andtext-underlineis not a valid Tailwind class.Step 2: Match the class to the underline effect
Since the question asks for adding underline,underlineis the correct class.Final Answer:
underline -> Option CQuick Check:
Underline class = underline [OK]
- Confusing underline with line-through
- Using no-underline to add underline
- Assuming text-underline exists
Solution
Step 1: Identify the class that removes underline
The classno-underlineremoves underline decoration from text.Step 2: Verify other options
underlineadds underline,line-throughcrosses out text, andtext-no-underlineis not a valid Tailwind class.Final Answer:
no-underline -> Option AQuick Check:
Remove underline = no-underline [OK]
- Using underline to remove underline
- Assuming text-no-underline exists
- Confusing line-through with no-underline
<p class="underline line-through text-red-500">Hello</p>
Solution
Step 1: Analyze the classes applied
The classesunderlineandline-throughadd underline and line-through decorations respectively.text-red-500colors the text red.Step 2: Understand combined text decorations
Both underline and line-through appear simultaneously, so the text will be underlined and crossed out in red color.Final Answer:
Text is underlined and crossed out in red color -> Option DQuick Check:
underline + line-through + red text = underlined & crossed out red text [OK]
- Thinking only one decoration applies
- Ignoring color class effect
- Assuming decorations override each other
<span class="underline text-underline-red">Sample</span>
Solution
Step 1: Check validity of classes
underlineis valid and adds underline.text-underline-redis not a valid Tailwind class for underline color.Step 2: Understand how to color underline
Tailwind usesdecoration-red-500or similar for underline color, nottext-underline-red.Final Answer:
text-underline-red is not a valid Tailwind class -> Option AQuick Check:
Invalid class name = text-underline-red [OK]
- Using text-underline-red instead of decoration-red-500
- Assuming underline color uses text- prefix
- Thinking underline can't be on span
Solution
Step 1: Choose classes for underline and color
underlineadds underline, anddecoration-green-600colors the underline green.Step 2: Avoid line-through classes
Since no line-through is wanted, do not addline-throughor any similar class. There is nono-line-throughclass in Tailwind.Final Answer:
underline decoration-green-600 -> Option BQuick Check:
Underline + green decoration, no line-through [OK]
- Adding non-existent no-line-through class
- Using text-green-600 colors text, not underline
- Including line-through by mistake
