Quick Reference Guide to CSS Pseudo-Classes

:hover

button:hover {
  background-color: #3498db;
  color: white;
}
      

:focus

input:focus {
  border: 2px solid #e67e22;
}
      

:active

button:active {
  background-color: #c0392b;
  color: white;
}
      

:visited

Visited link
a:visited {
  color: purple;
}
      

:nth-child(n)

li:nth-child(2) {
  color: blue;
}
      

:nth-of-type(n)

Paragraph 1

Paragraph 2 (styled)

p:nth-of-type(2) {
  color: green;
}
      

:first-child

I'm the first child

Second paragraph

p:first-child {
  background-color: #dff0d8;
}
      

:last-child

First paragraph

I'm the last child

p:last-child {
  background-color: #f9e79f;
}
      

:only-child

I'm the only child
div:only-child {
  color: red;
  font-weight: bold;
}
      

:checked

input:checked + label {
  color: green;
  font-weight: bold;
}
      

:disabled

input:disabled {
  background-color: #eee;
  color: gray;
}
      

:enabled

input:enabled {
  border: 2px solid green;
}
      

:not(selector)

This will be gray

This will be excluded

p:not(.special) {
  color: gray;
}
      

:nth-last-child(n)

li:nth-last-child(2) {
  color: orange;
}
      

:nth-last-of-type(n)

Span 1 Span 2 Span 3 (last-of-type)
span:nth-last-of-type(1) {
  color: blueviolet;
}