You are here:

Home / For students / HTML & CSS / CSS selectors /

CSS selectors

Most common selectors

SelectorDescriptionComment
*Any element (universal selector).
#elementIDAny element with id="elementID".A page should only have one element with a given id.
.enementClassAny element with class="elementClass".An element can have multiple classes separated by space.
divAny <div>.
div#divID.divClassAny <div> with id="id" and class="divClass".

Combinators

SelectorDescription
div, pany <div> and any <p>
div pany <p> inside a <div>
(does not have to be a direct child)
div > pany <p> which is a direct child of a <div>
div + pany <p> immediately after a <div>
SelectorDescription
a:linkunvisited link
a:visitedvisited link

Hover and click

SelectorDescription
.button:activeany element with class="button"
which is currently being clicked
.button:hoverany element with class="button"
which has the cursor hovering above it

Further reading

MDN
CSS selectors
w3school
CSS Selector Reference
upward arrowBack to top