CSS Selector Cheat Sheet
A complete reference for every CSS selector type — from basic element selectors to complex pseudo-classes and attribute matchers.
Last updated: May 21, 2026
Find this tool useful? Support the project to keep it free!
Buy me a coffeeWhat is CSS Selector Cheat Sheet?
CSS selectors determine which HTML elements a rule applies to. This cheat sheet covers all selector categories defined in the CSS specification: basic selectors, attribute selectors, structural pseudo-classes, UI pseudo-classes, pseudo-elements, and combinators.
Each entry shows the selector syntax, a brief description, and an example. Use it as a quick lookup when you need the exact syntax for an attribute selector or a specific `nth-child` expression.
How to Use CSS Selector Cheat Sheet
Common Use Cases
- Front-end developers looking up the exact syntax for :nth-child or attribute selectors.
- Students learning CSS who want a structured reference for all selector types.
- Code reviewers checking whether a selector is valid and what it targets.
- Developers migrating from a CSS framework to custom CSS who need selector basics.
Example Input and Output
Quick selector reference examples from the cheat sheet.
a[href^="https"]
p:nth-child(2n+1)
.card > .title
h2 ~ pLinks where href starts with "https"
Odd paragraph children
Direct .title children of .card
All <p> siblings after <h2>Browser support
Most selectors in this cheat sheet have universal browser support. Very new selectors (:has(), :is(), :where()) may have limited support in older browsers — check MDN or caniuse.com for specific version support.
Frequently Asked Questions
What is CSS specificity?
Specificity determines which CSS rule wins when multiple rules target the same element. ID selectors (0,1,0) beat class selectors (0,0,1) which beat element selectors (0,0,0,1). Inline styles (1,0,0,0) beat all. !important overrides all.
What is the difference between : and :: in CSS?
Single colon (:) is used for pseudo-classes (:hover, :focus, :nth-child). Double colon (::) is used for pseudo-elements (::before, ::after, ::first-line). Modern CSS requires :: for pseudo-elements, though single colon still works in most browsers for backwards compatibility.
Related Tools
CSS Validator
Validate CSS syntax online. Checks for unclosed braces, missing colons, empty rules, and invalid property/value pairs using CSS.supports().
CSS Beautifier / Formatter
Format, indent, and beautify minified or messy CSS code — with configurable indentation and sorting options.
CSS Minifier
Compress and minify CSS code to reduce file size and speed up page loads.
CSS to Tailwind Converter
Convert CSS declarations to Tailwind CSS utility classes — supports margin, padding, flex, grid, typography, colors, and arbitrary value fallbacks.
JSON Cheat Sheet
A complete JSON reference — data types, syntax rules, nested structures, common patterns, and gotchas. Quick lookup for developers working with JSON APIs and configs.
YAML Cheat Sheet
A complete YAML reference — scalars, sequences, mappings, multi-line strings, anchors, aliases, and gotchas. Quick lookup for developers working with YAML configs.

