- A CSS
pseudo-element
is a keyword added to a selector that lets you style a specific part of the selected element(s) -
For example,
::first-line
can be used to change the font of the first line of a paragraph syntax
selector::pseudo-element { property: value; }
-
Double colons (
::
) are used forpseudo-elements
-
This distinguishes
pseudo-elements
frompseudo-classes
that use a single colon (:
) in their notation -
Pseudo-elements
do not exist independently -
The element of which a
pseudo-element
is a part is called its originating element -
A
pseudo-element
must appear after all the other components in the complex or compound selector - The last element in the selector is the originating element of the pseudo-element
-
For example, you can select a paragraph's
first line using
p::first-line
but not the first-line's children -
So
p::first-line > *
is invalid -
A
pseudo-element
can be selected based on the current state of the originating element -
For example,
p:hover::first-line
selects the first line (pseudo-element) of a paragraph when the paragraph itself is being hovered (pseudo-class)