CSS Selectors

W3C CSS Snapshot 2026

A CSS selector tells the browser which elements a rule applies to. The main groups below include five basic selectors, selector lists, combinators, pseudo-classes, and pseudo-elements. Combinators express relationships, while pseudo-classes and pseudo-elements each contain many individual selectors.

On this page

Basic selectors (5)

  • Universal Selector (*)

    Use * to match any element. Combine it with another selector to limit the match to one part of the page.

  • Type Selector

    A type selector matches elements by their tag name.

  • Class Selector (.)

    Use a dot before a class name. You can reuse a class on several elements and give an element several classes.

  • ID Selector (#)

    Use # before an ID. Give each ID to just one element in the document.

  • Attribute Selector ([…])

    Use brackets to match an attribute by its presence or by a pattern in its value.

Selector lists

  • Selector List (,)

    Separate selectors with commas to apply one rule to anything that matches any selector in the list.

Combinators

Start with these four combinators for common HTML structures. The selectors specification also defines a column combinator.

Pseudo-classes

  • :hover

    Match an element while a pointing device points at it.

  • :focus-visible

    Match a focused element when the browser determines that a visible focus indicator is appropriate.

  • :checked

    Match a selected checkbox, radio button, or option.

  • :disabled

    Match a form control that the user cannot currently operate.

  • :nth-child()

    Match elements by position among siblings, counting from 1.

  • :first-child

    Match an element when it is its parent’s first element child.

  • :last-child

    Match an element when it is its parent’s last element child.

  • :is()

    Match any option in a selector list. Its specificity comes from the most specific argument.

  • :where()

    Match any option in its selector list without adding specificity for the arguments.

  • :not()

    Exclude elements that match a selector or any selector in a list.

  • :has()

    Match an element based on a relationship, for example when it has a matching child or next sibling.

Pseudo-elements

  • ::before

    Insert decorative generated content at the start of an element’s content.

  • ::after

    Insert decorative generated content at the end of an element’s content.

  • ::first-letter

    Style the first letter of the first formatted line in a block of text.

  • ::first-line

    Style the first displayed line in a block of text. Its length depends on the available width.

  • ::selection

    Style the text a user selects.

  • ::marker

    Style the bullet or number that marks a list item.

  • ::placeholder

    Style the hint text in an empty input or textarea.

Official references