B.1. Selector Examples

The following table should be used as a quick reference of CSS selector syntax. For more on selectors, see Chapter 13 and the end of this appendix.

Type of SelectorExampleSample Match (matched tag in bold for reference)
By nameh1, h2, h3<h2>
By class.booktitle<span class="booktitle">
By iddiv#logo<div id="logo">
By any attributeacronym[title]<acronym title="Ta Ta For Now">
As childdiv > p<div><p>
As grandchild or deeperdiv * p<div><form><p>
As child, grandchild, or deeperdiv p<div><p>
As sibling </th><td>th + td<tr><th scope="row">...
Pseudo-class:visited<a> (after being visited)

Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.