What Is CSS Specificity Calculator?
CSS Specificity Calculator is a free online tool by TechnSols that works out the specificity score of any CSS selector in seconds. Type or paste a selector such as .menu a.active or #header .nav li, and the tool shows its score at once, broken down into IDs, classes, and elements, so you can see at a glance why one rule wins.
A style that refuses to change is one of the most common frustrations in front end work. You write a new rule, refresh the page, and nothing happens, even though the code looks correct. The cause is usually specificity: an older rule with a higher score is beating your new rule, wherever the new rule sits. The CSS Specificity guide from Mozilla explains how browsers rank selectors, and this calculator turns that ranking into a number you can compare.
The tool scores selectors only, so it stays fast and simple. Paste one selector or a short list, read each score, and compare them side by side. The CSS Beautifier formats the code for easy reading, and the CSS Minifier shrinks it when the work is done. Everything runs in your browser, and no file is uploaded anywhere.
How To Use CSS Specificity Calculator?
Using CSS Specificity Calculator takes three quick steps. Paste a selector, read its score, and use the result to fix the rule that is losing. If the selector lives inside a page element you need to inspect first, the HTML Element Inspector shows the markup it belongs to.
Step 1: Paste Your CSS Selector
Type or paste selectors into the input box, one per line. A simple selector such as p or .card works, and so does a longer one such as #main .content ul li a:hover. Selectors separated by commas on one line are split apart and scored one by one. Clear the box and paste a new set whenever the next rule needs checking.
Step 2: Read The Specificity Score
The result shows the score as three numbers: IDs, classes, and elements. An ID counts in the first number, a class, attribute, or pseudo class counts in the second, and an element or pseudo element counts in the third. The columns never carry into each other, so one hundred classes at (0, 100, 0) still lose to a single ID at (1, 0, 0). Combinators and the universal selector add nothing. The breakdown shows which part of the selector is doing the heavy work.
Step 3: Compare And Fix Selectors
Paste the competing selectors together and read the ranked list. The highest score is the rule the browser applies, so the fix is clear: raise the losing selector by the smallest amount that wins, or lower the winning selector. When two selectors tie, the tool lists the first one entered first and says so, while in the browser the later rule wins the tie. Change the selector, paste it again, and check the new score before you save the stylesheet.
The whole check takes less than a minute, and it saves far longer hunts through a stylesheet. A score you can read beats a guess every time.
Why Do Specificity Conflicts Break Styles?
Specificity conflicts break styles because browsers do not apply the rule you wrote last. They apply the rule with the highest specificity, and only when two scores are equal does the later rule win. That order surprises many developers: a short rule written early can lose to a long rule written later.
The confusion grows as a stylesheet grows: a team adds IDs for quick fixes, then classes to fix the IDs, then longer selectors to fix the classes, and the scores climb higher and higher. The Selectors Standard from the World Wide Web Consortium defines this ranking, and every browser follows it. A style that loses a specificity battle can also leave text unreadable, which the Color Contrast Checker helps with.
A Small Rule Can Beat A Large Rule
A short selector with one ID beats a long selector with many classes and elements, because the ID column outranks everything else. A rule such as #sidebar p therefore beats .content .post .text p, even though the second selector is longer. The same surprise shows in numbers: #header .nav a scores (1, 1, 1) and beats .site .nav .menu .link a at (0, 4, 1), because the single ID decides the contest. The calculator shows this plainly once the two scores sit side by side.
IDs Outrank Classes And Elements
IDs carry the most weight in a selector, which is why experienced developers use them sparingly. Every ID raises the first number of the score, and only another ID can match it. Classes, attributes, and pseudo classes sit in the middle, and elements sit at the bottom. When a base style must stay easy to override, wrap it in :where(), which always scores zero: a reset such as :where(h1, h2, h3) sets margins without adding weight, so any single class beats it. Knowing this order helps you choose the lightest selector that does the job.
Later Rules Do Not Always Win
Source order only breaks a tie. When two selectors have the same score, the one that appears later in the stylesheet wins, and that is the only time order matters. If the scores differ, order changes nothing, which is why moving a rule to the bottom of the file so often fails. The score, not the position, decides the winner.
What Can You Do With CSS Specificity Calculator?
A specificity calculator fits any job where a style will not apply, or where a stylesheet has grown hard to control.
Fix A Button Style That Will Not Change
A button keeps its old colour even after you write a new rule for it. Paste the old selector and the new selector, compare the scores, and the reason appears at once: perhaps the old rule uses an ID, or chains three classes where the new rule uses one. Add one class to the new selector, or simplify the old one, and the button changes. When the button also needs a fresh look, the Gradient Generator builds a smooth background for it.
Clean Up A Stylesheet Full Of Overrides
A stylesheet full of overrides is a sign that specificity has drifted upward over time. Work through the worst rules, note the scores, and replace the heaviest selectors with lighter ones that still target the right elements. The same check settles a fight with a third party library: paste the library selector and your override side by side, and the scores show whether your rule can win. The page looks the same, but the stylesheet becomes shorter, calmer, and far easier to change next time.
Plan Selectors Before You Write Code
Planning selectors before writing code prevents conflicts instead of fixing them later. Decide on a simple pattern, such as one class per component and no IDs for styling, then check each new selector against it as you write. When a selector scores higher than the pattern allows, shorten it before it joins the file. The check also fits a pull request review: paste any selector a change adds and read its score before the code is merged. The Sass to CSS Compiler helps here too, because nested Sass can quietly produce long selectors that score higher than expected.
Quality And Settings
The calculator accepts any valid CSS selector, including combinators, pseudo classes, pseudo elements, and attribute selectors. It also handles the functional pseudo classes: :not(), :is(), and :has() take the score of their most specific argument only, never the sum, so :is(#main, .card) scores like #main alone. A dot or hash inside an attribute value is never counted. Every selector is ranked from highest to lowest, the winner is marked with a badge, and a plain sentence explains which column decided the contest.
- Score for any selector, with IDs, classes, and elements shown separately.
- Side by side ranking of a whole list, with the winner marked and explained.
- Support for :not(), :is(), :has(), :where(), pseudo classes, pseudo elements, and attribute selectors.
- Copy Report button and a downloadable text report of the full ranking.
- Plain word explanation of why the winner wins, naming the deciding column.
There are no other settings to learn, because the selector and its score are the whole tool. Paste the selectors, read the numbers, and act on them. The result is the same in every browser, because specificity is part of the CSS standard.
How CSS Specificity Calculator Works
The calculator reads the selector text entirely in your browser and counts its parts: each ID, each class, attribute, and pseudo class, and each element and pseudo element, then presents the three totals as the score. Attribute values are stripped first, so a dot or hash inside [href=”…”] never counts. The SCSS to CSS Compiler produces plain CSS from SCSS, and selectors from that output can be pasted here the same way.
One honest limit is worth knowing. The tool scores the selector you type, and it does not load a whole stylesheet or a live web page by itself. To check a rule from a page, copy the selector and paste it here. The Less to CSS Compiler works the same way: compile first, then paste the resulting selector for scoring.
Inline styles and the important flag sit outside the normal score. An inline style beats any selector, and an important declaration beats a normal declaration, but both are blunt tools that make later changes harder. The calculator scores selectors only, so it cannot settle a fight that involves either one. When two important rules compete, specificity decides between them again, so the score still matters. Fix the selector first, and reach for the blunt option only when the score shows no lighter way to win.
Privacy
Everything you check stays in your browser. The calculator runs on your own computer, and nothing you type is uploaded to a server, stored, or shared with anyone.
Because no account is needed, there is no name, email, or history tied to what you do. Closing the tab ends the session, and the browser clears the selectors from memory. That is the same protection on every tool here: your work stays yours.
Tips
A few habits make the calculator work smoother, whether this is your first check or your five hundredth.
- Keep IDs out of styling selectors whenever you can.
- Prefer one class per component over long chained selectors.
- Check the score before you add an important flag.
- Compare both selectors, not just the one that loses.
- Wrap a base reset in :where() so any class can override it.
When the scores explain the problem, the fix is usually a small one. If the page also needs a check on small screens, the Responsive Design Tester shows how the same styles behave at each width.
More Tools For The Same Job
These tools handle the same kinds of jobs: CSS, selectors, and colours.
- CSS Beautifier: formats messy CSS into clean, readable code.
- CSS Minifier: shrinks a stylesheet so it loads faster.
- HTML Element Inspector: shows the markup and attributes of any element.
- Color Contrast Checker: checks whether text colour stands out from its background.
- Gradient Generator: builds smooth colour gradients for backgrounds and buttons.
- Sass to CSS Compiler: turns Sass code into plain CSS in the browser.
- SCSS to CSS Compiler: turns SCSS code into plain CSS in the browser.
- Less to CSS Compiler: turns Less code into plain CSS in the browser.
- Responsive Design Tester: previews a page at phone, tablet, and desktop widths.
- SVG Editor and Previewer: edits SVG markup and previews the result at once.
FAQ
Common questions about CSS specificity scores, answered plainly.
Is CSS Specificity Calculator By TechnSols Free?
Yes, CSS Specificity Calculator by TechnSols is completely free to use, with no account, no sign-up, and no usage limit. You can check as many selectors as you like, and everything runs in your browser, so nothing is uploaded or stored anywhere.
How Is A Specificity Score Counted?
A specificity score has three numbers: IDs, classes, and elements. Each ID adds one to the first number, each class, attribute, or pseudo class adds one to the second, and each element or pseudo element adds one to the third. Combinators add nothing, and :where() always scores zero. The first number decides first, then the second, then the third.
Does Inline Style Always Win?
Yes, an inline style beats any selector, because it applies directly to the element and sits outside the normal scoring system. Only an important declaration can override it. It should be used rarely, since it is hard to override later and hard to find in a large page. A well chosen class selector is almost always the better fix.
What Does Important Do To Specificity?
An important declaration beats a normal declaration with the same property, whatever the selector scores are. It is a blunt override, and it creates a new problem: only another important declaration can beat it. Use it as a last resort, after the calculator shows the real scores.
Can I Check More Than One Selector?
Yes, paste a short list of selectors, one per line or separated by commas, and compare their scores side by side. When two selectors tie, the tool lists the first one entered first and explains the tie. Check the old rule and the new rule together, then change the losing selector and check it again.
Paste the selector, read the score, and fix the rule with the smallest change that wins. A stylesheet with low, even scores is easy to read and easy to change, and that is the whole point of checking specificity first.