3 min read
•Question 34 of 38mediumHow to use ::before and ::after in Tailwind?
Pseudo-element utilities.
What You'll Learn
- Before and after modifiers
- Content property
- Common patterns
Basic Usage
index.htmlHTML
<span class="before:content-['→'] before:mr-2">
Arrow before text
</span>
<span class="after:content-['*'] after:text-red-500">
Required field
</span>Empty Content
index.htmlHTML
<div class="before:content-[''] before:block before:h-1 before:bg-blue-500">
Has blue line above
</div>Absolute Positioning
index.htmlHTML
<div class="relative">
<span class="after:content-[''] after:absolute after:inset-x-0
after:bottom-0 after:h-0.5 after:bg-blue-500">
Underline effect
</span>
</div>Decorative Elements
index.htmlHTML
<blockquote class="relative pl-4 before:content-['']
before:absolute before:left-0 before:top-0
before:bottom-0 before:w-1 before:bg-blue-500">
Quote with left border
</blockquote>Tooltip Pattern
index.htmlHTML
<span class="relative group">
Hover me
<span class="invisible group-hover:visible absolute
before:content-[''] before:absolute
before:border-4 before:border-transparent
before:border-b-black">
Tooltip
</span>
</span>