The ::before pseudo-element lets you insert content before an element’s real content using only CSS. It is ideal for icons, labels, quotation marks, and other decorative prefixes without changing your HTML.
01
Generated content
Add visuals in CSS.
02
content
Required property.
03
Icons & text
Stars, notes.
04
display
Block vs inline.
05
::after
Before vs after.
06
A11y
Decorative only.
Fundamentals
Introduction
The ::before selector in CSS is a pseudo-element used to insert content before an element’s actual content. It creates a virtual child that appears at the start of the selected element.
This is commonly used for decorative symbols before headings, “Note:” labels before paragraphs, link icons, opening quotation marks, and custom list markers — all without adding extra HTML tags.
Definition and Usage
Every ::before rule must include the content property. The value can be text in quotes, an empty string "" for shape-based decorations, Unicode symbols like ★, or a function like attr(data-label).
By default, generated content is inline and flows on the same line as the element’s text. Use display: block when you need a prefix that sits on its own row.
💡
Beginner Tip
If your ::before rule does nothing, check that content is set. Without it, the pseudo-element is not generated at all.
“Design is not just what it looks like — design is how it works.
How It Works
\201C is the Unicode escape for a left double quotation mark. Pair with ::after and \201D for a closing quote if desired.
Watch Out
⚠️ Common Pitfalls
Forgetting content — Without it, ::before does not render at all.
Void elements — ::before does not work on img, input, br, and similar tags. Wrap them if needed.
Essential information — Do not put critical text only in generated content; screen readers may skip it.
Inline by default — For block-level decorations, set display: block or inline-block.
Single vs double colon — Prefer ::before to distinguish pseudo-elements from pseudo-classes.
A11y
♿ Accessibility
Decorative only — Use ::before for visuals that do not convey unique meaning.
Keep real text in HTML — Important labels, errors, and instructions belong in the document markup.
Screen readers — Generated content is often ignored; do not rely on it for essential context.
Link icons — Ensure the link text itself still makes sense without the decorative icon.
🧠 How ::before Works
1
CSS defines ::before
You write a rule with content and optional styles.
Rule
2
Browser creates a pseudo-box
A virtual box is inserted as the first child of the selected element.
Generate
3
Content and styles render
Text, icons, or empty shapes appear before the element’s real content.
Render
=
🎨
Richer design, same HTML
Visual polish without extra markup tags.
Compatibility
Browser Compatibility
The ::before pseudo-element is supported in all modern browsers. Very old browsers used the single-colon :before syntax.
✓ Universal · All browsers
Generated content everywhere
::before works reliably in Chrome, Firefox, Safari, Edge, and Opera on desktop and mobile.
99%Browser support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions
Full support
OperaAll versions
Full support
::before pseudo-element99% supported
Bottom line:::before is safe for decorative prefixes in any modern project.
Wrap Up
Conclusion
The ::before pseudo-element is a versatile tool for inserting content before elements without modifying HTML. From heading stars to link icons and opening quotes, it keeps markup clean while giving you fine control over presentation.
Remember the golden rule: always set content, keep essential information in real HTML, and pair ::before with ::after when you need decorations on both sides.
Keep generated content decorative or supplementary
Pair with ::after for balanced decorations
❌ Don’t
Put critical information only in ::before
Expect it to work on img or input directly
Forget that generated text may be ignored by screen readers
Overuse text in content for long paragraphs
Mix up ::before with ::after placement
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about ::before
Use these points when adding generated prefixes.
5
Core concepts
➕01
Before content
Inserts at the start.
Purpose
📄02
content
Required property.
Rule
⭐03
Icons & labels
Stars, notes.
Uses
🔀04
::after
Before vs after.
Pair
🌐05
99% support
All browsers.
Compat
❓ Frequently Asked Questions
The ::before pseudo-element inserts generated content immediately before an element's actual content. It is created purely in CSS without extra HTML.
Browsers only render ::before when content is defined. Use content with text, an empty string for decorative shapes, or functions like attr().
::before inserts content before the element's content. ::after inserts content after it. Both require the content property.
Void elements like img, input, and br do not have opening and closing content boxes in the same way, so ::before usually does not apply to them. Use a wrapper element instead.
Use the double-colon ::before syntax for pseudo-elements. Single-colon :before still works in older browsers but ::before is the modern standard.