CSS ::before
Pseudo-Element
The ::before
pseudo-element allows you to insert content before an element without modifying the HTML.
1. Basic Usage
✅ Adding Text Before an Element
✅ Adds a lightbulb emoji before every <p>
element.
2. Adding Icons or Symbols
✅ Adds a search icon before every <button>
.
3. Styling with CSS
You can style the ::before
content just like any other element.
✅ Creates a blue line above every <h1>
.
4. Using ::before
for Decorative Effects
✅ Bullet Points Before List Items
✅ Adds red bullet points before each <li>
.
5. Creating Animated Loading Text
✅ Shows "Loading..." when a button has the loading
class.
6. When to Use ::before
?
✔ Add icons, symbols, or decorative elements
✔ Enhance UI without extra HTML
✔ Create loading effects, labels, or tooltips