CSS selectors define the elements to which a set of CSS rules apply. They are similar to XPath in that they select a set of elements.
eltnameinput will match any <input> element.class attribute..classname.index will match any element that has a class of "index".id attribute. There should be only one element with a given ID in a document.#idname#toc will match the element that has the ID "toc".* ns|* *|** will match all the elements of the document.[attr] [attr=value] [attr~=value] [attr|=value] [attr^=value] [attr$=value] [attr*=value][autoplay] will match all elements that have the autoplay attribute set (to any value).+ combinator selects adjacent siblings. This means that the second element directly follows the first, and both share the same parent.A + Bh2 + p will match all <p> elements that directly follow an <h2>.~ combinator selects siblings. This means that the second element follows the first (though not necessarily immediately), and both share the same parent.A ~ Bp ~ span will match all <span> elements that follow a <p>.> combinator selects nodes that are direct children of the first element.A > Bul > li will match all <li> elements that are nested directly inside a <ul> element.A Bdiv span will match all <span> elements that are inside a <div> element.|| combinator selects nodes which belong to a column.A || Bcol || td will match all <td> elements that belong to the scope of the <col>.a:visited will match all <a> elements that have been visited by the user.p::first-line will match the first line of all <p> elements.This section needs more information.
| Specification | Status | Comment |
|---|---|---|
| Selectors Level 4 | Working Draft | Added the || column combinator |
| Selectors Level 3 | Recommendation | |
| CSS Level 2 (Revision 1) | Recommendation | |
| CSS Level 1 | Recommendation | Initial definition. |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors