Pseudo-Elements
๐ Covered in this chapter:
::before ยท ::after ยท ::first-letter ยท ::first-line ยท ::selection ยท ::placeholder ยท Decorative Content ยท Icons ยท Accessibility ยท Common Mistakes
Welcome to Chapter 6: Pseudo-Elements โ part of the CSS Complete Roadmap. This lesson covers all subtopics with clear explanations, code examples, and best practices used in professional web development.
1Pseudo-Classes vs Pseudo-Elements
| Type | Syntax | Purpose |
|---|---|---|
| Pseudo-class | :hover | Element state (existing element) |
| Pseudo-element | ::before | Virtual sub-part of element create/style |
CSS selectors element patterns ni match chesi styles apply chestayi; specificity and combinators selector behavior ni decide chestayi. Pseudo-elements decorative content and typography effects ki powerful.
2::before & ::after โ Decorative Content
Virtual elements create chestayi โ icons, badges, decorative lines. content property mandatory:
.quote::before {
content: "\201C";
font-size: 3rem;
color: #3b82f6;
line-height: 0;
}
.external-link::after {
content: " โ";
font-size: 0.85em;
}
Icons with pseudo-elements: Unicode symbols or icon fonts use cheyochu. SVG background-image kuda common pattern.
3::first-letter, ::first-line, ::selection, ::placeholder
CSS
p::first-letter {
font-size: 3em;
font-weight: 700;
float: left;
margin-right: 8px;
color: #2563eb;
}
p::first-line {
font-variant: small-caps;
}
::selection {
background: #bfdbfe;
color: #1e3a8a;
}
input::placeholder {
color: #94a3b8;
font-style: italic;
}
4Accessibility & Common Mistakes
โฟ Accessibility Considerations
::before/::aftercontent screen readers read cheyochu โ decorative ayitearia-hiddenon parent consider cheyandi- Important information pseudo-elements lo matrame pettakandi โ real HTML lo undali
::selectioncontrast sufficient ga maintain cheyandi
โ ๏ธ Common Pseudo-Element Mistakes
contentproperty marchakapovadam โ pseudo-element render avvadu- Single colon
:before(old CSS2 syntax) โ modern lo::beforeuse cheyandi - Replacing semantic HTML with
::beforecontent for labels/icons