CSS Selectors Reference
Interactive CSS selectors reference with examples and browser support. Master every selector type.
Basic Selectors
Fundamental selectors for targeting elements
*Selects all elements* { margin: 0; }<p>All elements</p>
elementSelects all elements of that typep { color: blue; }<p>Paragraph</p>
.classSelects elements with that class.highlight { background: yellow; }<p class="highlight">Highlighted</p>
#idSelects element with that ID#header { font-size: 2rem; }<div id="header">Header</div>
element, elementSelects multiple elements (grouping)h1, h2 { font-weight: bold; }<h1>Title</h1><h2>Subtitle</h2>
Combinator Selectors
Selectors that define relationships between elements
A BDescendant: B inside A (any depth)div p { color: red; }<div><p>Nested paragraph</p></div>
A > BChild: B is direct child of Aul > li { list-style: none; }<ul><li>Direct child</li></ul>
A + BAdjacent sibling: B immediately after Ah1 + p { margin-top: 0; }<h1>Title</h1><p>First paragraph</p>
A ~ BGeneral sibling: B after A (same parent)h1 ~ p { color: gray; }<h1>Title</h1><p>Any sibling p</p>
Pseudo-Class Selectors
Select elements based on state or position
:hoverMouse is over the elementa:hover { color: red; }<a>Hover me</a>
:focusElement has keyboard focusinput:focus { border-color: blue; }<input>
:activeElement being clicked/tappedbutton:active { transform: scale(0.98); }<button>Click</button>
:first-childFirst child of its parentli:first-child { font-weight: bold; }<ul><li>First</li><li>Second</li></ul>
:last-childLast child of its parentli:last-child { border: none; }<ul><li>First</li><li>Last</li></ul>
:nth-child(n)nth child of its parenttr:nth-child(2n) { background: #f5f5f5; }<tr>Even rows</tr>
:nth-of-type(n)nth of its type in parentp:nth-of-type(2) { color: blue; }<p>2nd paragraph</p>
:not(selector)Negation - everything except matchinput:not([type='submit']) { width: 100%; }<input type='text'>
:checkedChecked inputs (radio/checkbox)input:checked + label { font-weight: bold; }<input type='checkbox' checked>
:disabledDisabled form elementsinput:disabled { opacity: 0.5; }<input disabled>
:emptyElements with no childrendiv:empty { display: none; }<div></div>
:first-of-typeFirst of its type in parentp:first-of-type { font-size: 1.2em; }<p>First paragraph</p>
:focus-withinParent contains focused elementform:focus-within { box-shadow: 0 0 3px blue; }<form><input></form>
:has(selector)Parent contains matching childdiv:has(> img) { padding: 10px; }<div><img></div>
:is(list)Matches any selector in list:is(h1, h2, h3) { margin-top: 1em; }<h1>Heading</h1>
Pseudo-Element Selectors
Target specific parts of elements
::beforeInsert content before element.req::before { content: "*"; color: red; }<span class="req">Field</span>
::afterInsert content after element.ext::after { content: " ↗"; }<a class="ext">Link</a>
::first-lineFirst line of a block elementp::first-line { font-weight: bold; }<p>First line of text</p>
::first-letterFirst letter of a block elementp::first-letter { font-size: 2em; }<p>Drop cap</p>
::placeholderPlaceholder text of inputsinput::placeholder { color: #999; }<input placeholder='Type here'>
::selectionHighlighted/selected text::selection { background: #b3d4fc; }<p>Select this text</p>
::markerList item markers/bulletsli::marker { color: red; }<li>List item</li>
Attribute Selectors
Select elements based on their attributes
[attr]Element has attribute[required] { border-color: red; }<input required>
[attr="val"]Attribute equals exact value[type="email"] { width: 300px; }<input type="email">
[attr~="val"]Attribute contains word in space-separated list[class~="btn"] { cursor: pointer; }<div class="btn primary">OK</div>
[attr^="val"]Attribute starts with value[href^="https"] { color: green; }<a href="https://...">Secure</a>
[attr$="val"]Attribute ends with value[src$=".png"] { border: 1px solid; }<img src="photo.png">
[attr*="val"]Attribute contains value anywhere[href*="example"] { text-decoration: underline; }<a href="www.example.com">Link</a>
[attr|="val"]Attribute equals val or starts with val-[lang|="en"] { quotes: "“" "”"; }<p lang="en-US">English</p>
Disclaimer:This tool is provided “as is” for informational and educational purposes only. Results may not be 100% accurate. ToolBird makes no warranties, express or implied, regarding the accuracy, reliability, or completeness of any output generated by this tool. This tool does not constitute professional, legal, financial, medical, or tax advice. Always consult a qualified professional for important decisions. By using this tool, you agree that ToolBird and its operators shall not be held liable for any damages, losses, or consequences arising from the use of this tool or reliance on its results. All processing occurs in your browser — we do not store, transmit, or access your data. Use at your own risk.