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.
/* 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] {}
/* Adjacent sibling combinator */
A + B {}
/* General sibling combinator */
A ~ B {}
/* Child combinator */
A > B {}
/* Descendant combinator */
A B {}
/* Column combinator */
A || B {}
/* Pseudo-classes */
a:visited {}
a:hover {}
a:active {}
a:focus {}
/* Pseudo-elements */
p::first-line {}
p::before {}
p::after {}
Useful resources on CSS selectors:
- W3C CSS Selectors Level 3 Specification
- W3C CSS2.1 Specification's Selectors Section
- Desktop Browsers Compatibility on QuirksMode
- Mobile Browsers Compatibility on QuirksMode
- Getting Started with CSS Selectors on MDN
- Attribute selectors on MDN
Future Implementations: