CSS Specificity Calculator
Calculate the specificity of any CSS selector as (inline, ID, class, element) notation.
Compare two selectors to see which one wins the cascade. Supports pseudo-classes, pseudo-elements, attribute selectors, :not(), :is(), :where(), and combinators.
Score: 10200
Specificity Scoring Rules
Try an example
Frequently Asked Questions
What is CSS specificity?▼
CSS specificity is the algorithm browsers use to determine which CSS rule applies when multiple rules match the same element. It is represented as a 4-part value (inline, ID, class, element). Higher specificity wins. When two selectors have equal specificity, the one declared later in the stylesheet wins (the cascade).
How is CSS specificity calculated?▼
Specificity is calculated as four separate columns: (inline, ID, class, element). Inline styles = 1,0,0,0. ID selectors (#foo) = 0,1,0,0. Class selectors (.foo), attribute selectors ([type='text']), and pseudo-classes (:hover) = 0,0,1,0. Element selectors (div, p) and pseudo-elements (::before) = 0,0,0,1. Combinators (+, ~, >, space) and the universal selector (*) contribute 0.
Which selector wins: .nav a vs nav a.link?▼
.nav a has specificity (0,0,1,1) — one class + one element. nav a.link has specificity (0,0,1,2) — one class + two elements. nav a.link wins because (0,0,1,2) > (0,0,1,1). Specificity is compared column by column from left to right; a tie in one column is broken by the next.
Does !important override specificity?▼
Yes. !important overrides the normal specificity algorithm entirely — an !important declaration always wins against a non-!important declaration, regardless of specificity. However, if two competing declarations both use !important, specificity is compared again. Using !important excessively makes CSS hard to maintain; prefer increasing specificity or restructuring your selectors.
What is the specificity of :not()?▼
The :not() pseudo-class itself contributes 0 to specificity, but its argument does count. For example, :not(.active) has specificity (0,0,1,0) because .active is a class selector. The same applies to :is() and :has() — the most specific argument within them is counted.
Why does :where() have zero specificity?▼
:where() was specifically designed to have zero specificity for all its arguments. This is useful for writing base styles or resets that you want to override easily without increasing specificity. Unlike :is() or :not(), :where(h1, h2, h3) always contributes (0,0,0,0).
Related Products
on GumroadDevPlaybook Interview Vault
210+ real technical interview questions with model answers, asked at Google, Meta, Amazon, Microsoft, Stripe, and Shopify. Covers Frontend (55), Backend (55), System Design (50), and DSA (50). Available in English and Traditional Chinese.
Buy on Gumroad →TypeScript Quick Reference Toolkit
5 practical reference files for TypeScript developers: cheatsheet, TS vs JS comparison, 20 utility types with real examples, tsconfig best practices template, and 15 common mistakes guide. Print it. Keep it on your desk.
Buy on Gumroad →Developer Interview Vault
210 technical interview questions with model answers, key points, and follow-up questions. Covers Frontend, Backend, System Design, and DSA — bilingual English + Traditional Chinese (ZH-TW). PWYW from $29.
Buy on Gumroad →You Might Also Need
Webhook Tester
Generate realistic webhook test payloads for GitHub, Stripe, Slack, and custom services. Get a curl command to send the payload to your local endpoint. Inspect headers, payload size, and content-type.
Open free tool →
CSS Clip-Path Generator
Generate CSS clip-path values visually. Choose from 16 polygon presets (triangle, star, arrow, hexagon), circle, ellipse, and inset shapes. Live preview, one-click copy. Free, no signup.
Open free tool →
WebSocket Tester
Connect to any WebSocket server, send and receive messages in real time, and inspect the message log with timestamps and byte sizes. Free online WebSocket client.
Open free tool →
More Free Tools
Related Articles
CSS Gradient Generator Online: Create Linear, Radial & Conic Gradients Free
Generate beautiful CSS gradients online for free. Build linear, radial, and conic gradients visually, copy the CSS code, and use it instantly in your project — no install needed.
CSS Gradient Guide 2026: Linear, Radial, Conic, and Advanced Patterns
Master CSS linear, radial, and conic gradients with copy-paste code. Includes performance tips, animation techniques, dark mode handling, gradient mesh alternatives, and production UI design recipes.
CSS Grid vs Flexbox: Complete Guide with Interactive Examples 2025
CSS Grid vs Flexbox with real code examples for every common layout pattern. Holy Grail layout, card grid, navigation bar, sidebar — see exactly when to use each one.
CSS Container Queries: The Complete Guide for Modern Web Development (2026)
Master CSS container queries including @container, container-type, container-name, style queries, size queries, and how to build truly responsive components without media queries.
Tailwind CSS v4: Everything Changed (Migration Guide 2026)
Complete guide to migrating from Tailwind CSS v3 to v4. CSS-first configuration, new utility classes, and step-by-step migration checklist.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →