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).

| LIVE PREVIEW

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 the content of ::before
  • If there's other content before the first letter (like <img>), the first letter won't get the style
| LIVE PREVIEW

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.

| LIVE PREVIEW

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>).

| LIVE PREVIEW
  • 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.)

| LIVE PREVIEW

::placeholder

Styles the placeholder of an <input>.

| LIVE PREVIEW

UI

::backdrop

Sets the "background" of an element being presented full-screen.

| LIVE PREVIEW

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.

| LIVE PREVIEW

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