CSS Selector Tester
Master CSS specificity with this real-time selector debugger. Visualize matches, calculate specificity scores (0-0-0), and translate complex selectors into plain English.
About
CSS (Cascading Style Sheets) relies heavily on the concept of Specificity to determine which styles apply to an element when multiple rules conflict. Understanding the mechanics of selector matching is not just academic; it is critical for preventing !important wars and maintaining scalable, clean codebases. This tool provides a deterministic environment to test selector logic against live DOM structures, helping developers eliminate guesswork.
Common pitfalls include over-qualifying selectors (e.g., div.nav instead of .nav), which artificially inflates specificity, making future overrides difficult. By visualizing the A-B-C specificity weight and translating cryptic selector strings into natural language, this utility bridges the gap between intended design and browser implementation.
Formulas
Specificity is calculated as a tuple ABC, where higher values in a column outweigh any number of values in columns to the right. The calculation algorithm is defined as:
Example: The selector #nav .item > a:hover breaks down into:
Reference Data
| Selector Pattern | Description | Specificity (A-B-C) | Example |
|---|---|---|---|
| * | Universal Selector | 0-0-0 | * |
| element | Type Selector | 0-0-1 | div, span |
| .class | Class Selector | 0-1-0 | .container |
| #id | ID Selector | 1-0-0 | #header |
| [attr] | Attribute Selector | 0-1-0 | [type="text"] |
| :pseudo-class | State/Structural | 0-1-0 | :hover, :nth-child() |
| ::pseudo-element | Virtual Elements | 0-0-1 | ::before, ::placeholder |
| +, >, ~ | Combinators | 0-0-0 | div > p |