CSS selectors define the elements to which a set of CSS rules apply.
- Type selector
- Selects all elements that match the given node name.
input will match any
- Class selector
- Selects all elements that have the given
.index will match any element that has a class of "index".
- ID selector
- Selects an element based on the value of its
id attribute. There should be only one element with a given ID in a document.
#toc will match the element that has the ID "toc".
- Universal selector
- Selects all elements. Optionally, it may be restricted to a specific namespace or to all namespaces.
* will match all the elements of the document.
- Attribute selector
- Selects elements based on the value of the given attribute.
[autoplay] will match all elements that have the
autoplay attribute set (to any value).
- Adjacent sibling combinator
+ combinator selects adjacent siblings. This means that the second element directly follows the first, and both share the same parent.
A + B
h2 + p will match all
<p> elements that directly follow an
- General sibling combinator
~ combinator selects siblings. This means that the second element follows the first (though not necessarily immediately), and both share the same parent.
A ~ B
p ~ span will match all
<span> elements that follow a
- Child combinator
> combinator selects nodes that are direct children of the first element.
A > B
ul > li will match all
<li> elements that are nested directly inside a
- Descendant combinator
combinator selects nodes that are descendants of the first element.
div span will match all
<span> elements that are inside a
- Pseudo-classes allow the selection of elements based on state information that is not contained in the document tree.
a:visited will match all
<a> elements that have been visited by the user.
- Pseudo-elements represent entities that are not included in HTML.
p::first-line will match the first line of all
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
||1.0 (1.7 or earlier)
||Firefox Mobile (Gecko)
Document Tags and Contributors