Pseudo-classes

What are Pseudo-classes?

A pseudo-class selects elements in a special state or position, written with one colon: a:hover, li:first-child.

Pseudo-classSelects
:hover, :activeelement under the mouse / being clicked
:focus, :focus-visibleelement with keyboard focus
:visited, :linkvisited / unvisited links
:first-child, :last-childfirst / last child of its parent
:nth-child(2n)every 2nd child (even); odd, 3n+1...
:not(.x)elements that do not match .x
:checked, :disabled, :invalidform states

Example

Example

Hover over the button and the list items:

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    button { background: #04AA6D; color: white; border: 0; padding: 8px 16px; }
    button:hover { background: #282A35; }
    li:nth-child(odd) { background: #f1f1f1; }
    li:hover { color: #04AA6D; }
    li:last-child { font-weight: bold; }
    input:invalid { border: 2px solid red; }
  </style>
</head>
<body>

<button>Hover me</button>
<ul>
  <li>One</li><li>Two</li><li>Three</li><li>Four (last)</li>
</ul>
<input type="email" value="not-an-email">

</body>
</html>

Result