Skip to main content
A Frehner Site

Pseudo Elements & Classes

Pseudo Confusion #

I've always just kind of lumped CSS's pseudo-classes and pseudo-elements together and thought they were the same thing. I'm not sure it really ever made a difference in how I wrote styles for them, and it likely didn't help that early pseudo-elements were written the same way as pseudo-classes.

I've also seen pseudo-classes referred to as "pseudo-selectors" which muddies the water, since I believe that term encompasses both pseudo-classes and pseudo-elements.

And even now I have a hard time remembering how many colons to put for elements vs selectors.

All of that is to say: it can be hard. 🙂

So what is the difference? #

To be lazy, this MDN article lays it out fairly well, but ultimately the names themselves give good hints as to their difference:

The Open-UI proposal for the new Select element (such an exciting proposal, by the way) has some good examples of CSS styling that contains both pseudo-classes and pseudo-elements. Look at this beautiful mix:

select option:hover {
	background-color: SelectedItem;
	color: SelectedItemText;
}

select option::before {
	content: "\2713"/ "";
}

select option:not(:checked)::before {
	visibility: hidden;
}