CSS Pseudo Elements
What are Pseudo Elements?
Pseudo-elements style specific parts of an element or insert content. They
use double colons :: (single colon also works for legacy
support).
Before & After
::before and ::after insert content before or
after an element. Requires the content property!
Decorative Icons
Use ::before to add icons or decorative elements without
cluttering HTML.
First Letter
::first-letter styles the first letter of a block
element. Perfect for drop caps!
First Line
::first-line styles the first line of text in a
block element.
Clearfix with After
A classic use of ::after is the clearfix hack
for containing floated elements.
::before
and ::after MUST have a
content property, even if it's empty:
content: '';
Summary
::before- Insert content before element::after- Insert content after element::first-letter- Style first letter::first-line- Style first linecontentproperty is required for ::before/::after- Use for decorative elements, not essential content
Quick Quiz
Which property is required for ::before and ::after?
Enjoying these tutorials?