CSS selectors Edit on GitHub In category: CSS

Basic selectors #selectors

Selector Meaning
* All elements in DOM tree
div All div tags
div, span All div and span tags
#source Element with ID source
.important All elements with class important
pre#source pre tag with id source
li.important All li tags with class important
#code * All elements nested in #code
li.important > a All links nested directly in li.important
li.important a All links nested (directly or not) in li.important
input[required] input tags with attribute required
button[type="result"] Buttons with type set to reset
a[href*="google"] All links with href containing phrase google

Pseudo-elements #pseudo-elements

Also known as pseudo-selectors.

Selector Notes
::after None.
::before None.
::first-letter First letter of the first line in a block element. More details .
::first-line First line of an element.
::selection Selected text. More.


According to CSS 3 specification, pseudo elements must be prefixed with double colon (::), to distinguish them from pseudo classes. However, note that IE 8 and below does not support this notation. CSS 2 spec uses single colon.

Comments #comments