CSS selectors are patterns that choose which HTML elements receive styles. They sit before the curly braces in a rule and answer one question: who should this CSS apply to?
Selector vs property
A selector picks the elements (.btn). A property chooses what to change (background-color). A value sets how (#2563eb). Together they form a rule: .btn { background-color: #2563eb; }.
What should beginners learn first?
Master .class, element selectors (element), #id sparingly, descendant combinators, and :hover / :focus for interaction. Those cover most CSS tutorial work before attributes and advanced pseudo-classes.
Hub vs single-selector pages
This page teaches how selectors work in a CSS tutorial. Each name in the index links to a focused guide (for example CSS .class Selector). For the declarations you apply after matching, see CSS Properties; for responsive conditions, see Media Queries.
Prefer classes.
Use .class for reusable components. Reserve #id for unique landmarks or script hooks—high specificity makes overrides harder.
Keep selectors short.
.card-title beats deep chains like div div h3 span. Long selectors are fragile when HTML changes.
Match HTML first.
Selectors only work if the markup has the tags, classes, or attributes you target. Write clear HTML, then style it.
Syntax
CSS Syntax
Every rule pairs a selector with a declaration block:
CSS
/* Element */p{color:#334155;}/* Class */.highlight{background:#fef08a;}/* ID */#footer{text-align:center;}/* Pseudo-class */a:hover{text-decoration:underline;}/* Combinator + attribute */nav a[href^="https"]{color:#059669;}
Reference
Core CSS Concepts
Selector families you will use throughout this CSS tutorial:
Most selector mistakes are over-specific IDs, deep chains, or missing focus styles.
#id
Overusing IDs for styling
High specificity makes overrides painful. Prefer classes for visual styles.
nest
Deep descendant chains
div div div p breaks when markup shifts. Use a class on the real target instead.
*
Universal selector everywhere
* touches every element. Fine in a careful reset; risky as a default styling tool.
:h
Hover-only interactions
Touch devices may never hover. Keep actions visible and style :focus too.
::
Missing content on ::before
Pseudo-elements need a content value (even "") to render.
a11y
Removing :focus outlines
Never drop focus styles without a visible replacement. Keyboard users depend on them.
Compatibility
Browser Support
Core CSS selectors—element, class, ID, combinators, :hover, :focus, and basic attribute selectors—are Baseline CSS. Newer selectors like :has() vary; each guide notes its own support.
✓ Baseline · Widely available
CSS selectors
Essential selectors work in all major browsers. Check individual tutorials for newer pseudo-classes.
100%core selectors
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
Core CSS selectorsUniversal
Bottom line: Learn .class, element, combinators, and :hover/:focus first—they are production-safe. Newer selectors document compatibility on their own pages.
Remember
Key Takeaways
Selectors choose which elements a CSS rule styles.
Start with.class, elements, then :hover / :focus.
Specificity: IDs > classes > elements—prefer lower when you can.
One line: Selectors target HTML for styling—favor classes, keep them short, learn specificity, then open guides from the index.
Frequently Asked Questions
CSS selectors are patterns that tell the browser which HTML elements to style. They appear before the declaration block: selector { property: value; }. Examples include p, .card, #header, and a:hover.
A class selector (.name) can match many elements and is reusable. An ID selector (#name) should match only one element per page. Prefer classes for most styling; reserve IDs for unique landmarks or JavaScript hooks.
Specificity decides which rule wins when multiple selectors target the same element. IDs beat classes, classes beat elements, and inline styles beat stylesheet rules. Lower specificity is easier to maintain.
Pseudo-classes (:hover, :focus) describe element state or position. Pseudo-elements (::before, ::first-letter) style a part of an element. Use one colon for pseudo-classes and two for pseudo-elements.
Combinators connect selectors to express relationships: descendant (space), child (>), adjacent sibling (+), and general sibling (~). They style elements based on where they sit in the HTML.
Open the .class tutorial first, then element and :hover. Use the searchable index for any of the selector guides, then pair selectors with CSS Properties to finish each rule.