Skip to main content

Selectors are patterns that match against elements in a document tree. In a CSS rule, they are used to define styles for elements that match the pattern.

Selectors are patterns that match against elements in a document tree. In a CSS rule, they are used to define styles for elements that match the pattern.

Simple selectors:

/* Type selector */  
eltname {}

/* Class selector */
.classname {}

/* ID selector */
#idname {}

/* Universal selector */
* {}

/* Attribute selector */
[attr] {}
[attr=value] {}
[attr~=value] {}
[attr|=value] {}
[attr^=value] {}
[attr$=value] {}
[attr*=value] {}

Combinators

/* Adjacent sibling combinator */
A + B {} 

/* General sibling combinator */
A ~ B {}

/* Child combinator */
A > B {}

/* Descendant combinator */
A B {}

/* Column combinator */
A || B {}

Pseudo-classes

/* Pseudo-classes */
a:visited {}
a:hover {}
a:active {}
a:focus {}

Pseudo-elements

/* Pseudo-elements */
p::first-line {}
p::before {}
p::after {}

Useful resources on CSS selectors:

Future Implementations: