The ::after pseudo-element lets you insert content after an element’s real content using only CSS. It is ideal for decorative lines, icons, and visual extras without changing your HTML.
01
Generated content
Add visuals in CSS.
02
content
Required property.
03
Decorations
Lines, icons, text.
04
display
Block vs inline.
05
::before
Before vs after.
06
A11y
Decorative only.
Fundamentals
Introduction
The ::after selector in CSS is a pseudo-element used to insert content after an element’s actual content. It creates a virtual child that appears at the end of the selected element.
This is commonly used for decorative lines under headings, icons after links, quotation marks, badges, and other presentational touches — all without adding extra HTML tags.
Definition and Usage
Every ::after rule must include the content property. The value can be text in quotes, an empty string "" for shape-based decorations, or a function like attr(data-label).
By default, generated content is inline. Use display: block when you need a line or box that sits on its own row, such as an underline bar below a heading.
💡
Beginner Tip
If your ::after rule does nothing, check that content is set. Without it, the pseudo-element is not generated at all.
This is an example paragraph. - Thanks for reading!
How It Works
Text in content is inserted inline at the end of the paragraph. Screen readers may ignore decorative generated text, so do not hide important meaning here alone.
📄 UI Patterns
Use ::after for icons and form markers in real interfaces.
Example 3 — External link icon
Append an arrow after links that open external sites.
The asterisk is decorative. Also use the HTML required attribute and/or aria-required="true" so assistive technology understands the field is mandatory.
Watch Out
⚠️ Common Pitfalls
Forgetting content — Without it, ::after does not render at all.
Void elements — ::after 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 ::after to distinguish pseudo-elements from pseudo-classes.
A11y
♿ Accessibility
Decorative only — Use ::after for visuals that do not convey unique meaning.
Keep real text in HTML — Important labels, errors, and instructions belong in the document markup.
Required fields — Pair decorative asterisks with required and accessible label text.
External link icons — Ensure the link text itself still makes sense without the icon.
🧠 How ::after Works
1
CSS defines ::after
You write a rule with content and optional styles.
Rule
2
Browser creates a pseudo-box
A virtual box is inserted as the last child of the selected element.
Generate
3
Content and styles render
Text, icons, or empty shapes appear after the element’s real content.
Render
=
🎨
Richer design, same HTML
Visual polish without extra markup tags.
Compatibility
Browser Compatibility
The ::after pseudo-element is supported in all modern browsers. Very old browsers used the single-colon :after syntax.
✓ Universal · All browsers
Generated content everywhere
::after 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
::after pseudo-element99% supported
Bottom line:::after is safe for decorative enhancements in any modern project.
Wrap Up
Conclusion
The ::after pseudo-element is a versatile tool for inserting content after elements without modifying HTML. From heading underlines to link icons, 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 ::after with ::before when you need decorations on both sides.
Keep generated content decorative or supplementary
Use ::after with classes for targeted effects
❌ Don’t
Put critical information only in ::after
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 ::after with ::before placement
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about ::after
Use these points when adding generated content.
5
Core concepts
➕01
After content
Inserts at the end.
Purpose
📄02
content
Required property.
Rule
🖼03
Decorations
Lines, icons, text.
Uses
🔀04
::before
Before vs after.
Pair
🌐05
99% support
All browsers.
Compat
❓ Frequently Asked Questions
The ::after pseudo-element inserts generated content immediately after an element's actual content. It is created purely in CSS without extra HTML.
Browsers only render ::after 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 ::after usually does not apply to them. Use a wrapper element instead.
Use the double-colon ::after syntax for pseudo-elements. Single-colon :after still works in older browsers but ::after is the modern standard.