← Cheat Sheets

CSS Selectors

Select elements precisely.

# CSS Selectors

Select elements precisely.

| Selector | Selects |
|---|---|
| `*` | Everything |
| `p` | By tag |
| `.card` | By class |
| `#main` | By id |
| `a b` | Descendant |
| `a > b` | Direct child |
| `a + b` | Next sibling |
| `a ~ b` | Any following sibling |
| `[type="text"]` | Attribute equals |
| `[href^="https"]` | Attribute starts with |
| `[href$=".pdf"]` | Attribute ends with |
| `[class*="btn"]` | Attribute contains |
| `:not(.x)` | Not matching |
| `:is(h1, h2)` | Any in the list |
| `:has(img)` | Parent that contains a match |