CSS - Pseudo-elements
Overview
Quick links: Exercises • Checks • Print as PDF
Estimated time: 10 minutes
Pseudo-elements style parts of elements or insert generated content without extra markup.
Learning Objectives
- Use
::beforeand::afterfor badges and decoration. - Style typographic parts like
::first-lineand list::marker.
Details & Examples
Pseudo-elements let you style parts of an element or insert generated content.
::before/::afterfor decoration and badges::first-line,::first-letterfor typographic effects::markerto style list bullets::selectionto style text selection
Pseudo-elements demo paragraph for selection and first-line.
- Item A
- Item B
- Item C
Checks for Understanding
- How would you add a decorative bullet without extra markup?
Show answers
- Use
::beforeor::markerdepending on context.
Exercises
- Add a "NEW" badge before a product title using
::before. - Style list
::markerwith a brand color.
Suggested answers
.title::before{ content:"NEW"; ... }li::marker{ color: #22c55e; }