Cover image for 8 Unfamiliar CSS Pseudo-Classes

8 Unfamiliar CSS Pseudo-Classes

frontenddude profile image Frontend Dude 👨‍💻 ・2 min read

'A CSS pseudo-class is a keyword added to a selector that specifies a special state of the selected element(s).' - MDN Web Docs

Wait....what? That sounds complicated right?

What if I told you, you might be surprised to know you are already using them?

Of course you are! Here's an example of the syntax used, can you think of any pseudo classes you have used before?

selector:pseudo-class {
  property: value;

Let me guess, you thought of :hover, maybe even ::before and :after? If so, great job! However, there are many others we can use to improve our sites. Lets check out 8 unfamiliar ones below:


Selects inputs, radio or options in select tags that have been toggled "on" by a user clicking on them.

/* Any checked element */
:checked {

/* input checkbox example */


Selects any element that is 'empty'.

An element is empty if it has no whitespace, visible content or child elements.

/* style an empty element */
:empty {
    border:1px solid red;


Selects the element that represents the root of the document.

:root is identical to using html as a selector, except is has a higher specificity.

/* style the root element */
:root {


Selects any link that has already been visited on the page.

It will only select anchor tags that have a href attribute.

/* style a link thats been visited */
a:visited {
    font-weight: bold;


Used to style elements that have range limitations such as inputs with min and max values.

The style is applied whilst its value is within the range limit.

/* style in-range */


Selects an element if it is its parents only child.

It can be chained with :hover and ::after.

/*  style only-child */
    font-weight: bold;

/* chained example */
    content: "(Only child)";


Selects form elements that have the required attribute set.

s, s and s are valid selections.

/*  style required input */
    border:2px solid red;


Selects the area of the document that is highlighted by the user.

Color, background-color and text-shadow are the only CSS properties that can be used.

/* all selectable elements */

/* specific element */
    background-color: white;

The basis of this post stems from the popularity of the tweet linked below. If you found it useful or learnt something new please follow me on twitter where I post daily tips on HTML, CSS and JavaScript.

Posted on by:

frontenddude profile

Frontend Dude 👨‍💻


Follow @frontenddude for daily FrontEnd development tips.


Editor guide

This is very cool. I feel like CSS is still a big mystery to me despite first coming across it in 2001, I’ve never sat down and properly learned it and some of the stuff you can do without JS is pretty amazing.


It's a lot deeper than most people think. The possiblities are almost endless seeing as its a cornerstone technology of the World Wide Web.


Nice! :invalid is also a great one for styling form items that aren't filled out correctly, like email inputs.


Thanks and great input. (pun intended XD)

Will definately be using :invalid in the future. Thanks


Amazing. Thank you so much!


Thanks so much for supporting my article