Selectors

A selector decides which elements a CSS rule applies to. There are a few basic kinds you'll use constantly.

Element selector

Targets every element of a given tag name:

Try it yourself
Result

Class selector

Targets any element with a matching class attribute. Written with a leading period:

Try it yourself
Result

ID selector

Targets the one element with a matching id attribute. Written with a leading hash symbol. An id should only be used once per page.

Try it yourself
Result

Grouping selectors

Apply the same rule to several selectors at once by separating them with commas:

Try it yourself
Result