Pseudo Elements
This lists all available pseudo elements (omitting some that are obscured, experimental, or unlikely to be used).
Texts
::before
Inserts content
before an element (it's inline by default).
::after
Inserts content
after an element (it's inline by default).
One two three
::first-letter
Styles the first letter of an element's text content.
- If the content is modified by
::before
, then the "first letter" could be in thecontent
of::before
- If there's other content before the first letter (like
<img>
), the first letter won't get the style
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas in ullamcorper nisl, eget congue ligula. Sed elit lacus, interdum eget leo nec, pulvinar maximus libero. Aliquam vehicula, ipsum eget tincidunt lobortis, sem nisi facilisis felis, fermentum dapibus est urna ut purus.
::first-line
Styles the first line of an element's text content.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas in ullamcorper nisl, eget congue ligula. Sed elit lacus, interdum eget leo nec, pulvinar maximus libero. Aliquam vehicula, ipsum eget tincidunt lobortis, sem nisi facilisis felis, fermentum dapibus est urna ut purus.
Lists
::marker
Styles the bullet/marker of a "list item" (basically anything that has display: list-item
, like <li>
or <summary>
).
- One
- Two
- Three
Forms
::file-selector-button
Styles the button part of an <input type="file">
.
(If you use input[type="file"]
, it will also style other parts of the file input, like the current selected filename.)
::placeholder
Styles the placeholder of an <input>
.
UI
::backdrop
Sets the "background" of an element being presented full-screen.
Try pressing fullscreen. You won't see the red background if your screen size matches the size of the poster/thumbnail or the video.
::selection
Styles part of the document that has being highlighted.
Try selecting this text!
Omitted
I decided to not include the following (because they're super obscured, or still experimental at the time of writing). You can read more about them on MDN.
Text Fragments:
::grammar-error
::spelling-error
::target-text
Subtitles:
::cue
::cue-region
Shadow DOM:
::part(...)
::slotted(...)
References
- Pseudo Elements (MDN) — https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements
- ::marker (MDN) — https://developer.mozilla.org/en-US/docs/Web/CSS/::marker