CSS Specificity Calculator and Cascade Explainer
Paste selectors to see their (A, B, C) score and breakdown, chart specificity across a stylesheet, and model origins, layers and !important.
브라우저에서 실행됩니다. 파일은 기기 밖으로 나가지 않습니다. 확인하는 방법 보기
…
사용 방법
- 1Open the calculator tab
Paste selectors, one per line; comma lists are split for you.
- 2Read the breakdown
Each chip shows the simple selector and how much it adds.
- 3Sort and compare
Tick sort to put the strongest selector first.
- 4Graph a stylesheet
Paste CSS in the stylesheet tab and look for spikes in the chart.
- 5Model the cascade
Add competing declarations with origin, layer, !important and order.
- 6Export
Download the specificity table as CSV or copy the winning declaration.
이 도구 소개
When a style does not apply, the reason is almost always the cascade: another rule with a higher specificity, a later layer, an !important somewhere, or simply a rule that comes later in the file. Specificity is a three-part score. The first number counts ID selectors, the second counts classes, attribute selectors and pseudo-classes, and the third counts element names and pseudo-elements. Scores are compared column by column, so one ID always beats any number of classes. Modern CSS adds twists that many older calculators get wrong: :is(), :not() and :has() take the score of their most specific argument, :where() always counts zero, and :nth-child(2n of .x) adds the selector inside it. This tool implements those Selectors Level 4 rules, shows how each part of a selector contributes, and goes one step further by explaining the full cascade order, including origins, cascade layers and importance.
Selector calculator
Type or paste selectors, one per line; comma-separated lists are split into separate selectors because each one in a list has its own score. Every result shows the (A, B, C) score and a row of coloured chips, one per simple selector, with what each adds. You can sort by score to see the strongest selector at the top. Legacy single-colon pseudo-elements such as :before and :first-line are counted as pseudo-elements, the way browsers treat them. Syntax mistakes like a double dot or an unclosed bracket are reported with their position.
Stylesheet graph
Paste a whole stylesheet and every selector is listed with its line number. A line chart plots a single score (A×100 + B×10 + C) in source order. A well-organised stylesheet climbs gently from resets and element styles to components and utilities; sharp spikes are the rules that later forced someone to write an even stronger selector or reach for !important. Red dots mark selectors with IDs. The table of the 25 most specific selectors downloads as CSV for a refactoring ticket. Keyframe stops and at-rule preludes are skipped.
Who wins
The cascade tab lets you enter competing declarations for one property. For each you set the origin (browser default, user, author, inline style, animation or transition), the cascade layer, !important, the selector and the source order. The tool sorts them in the order the CSS Cascade Level 5 specification defines and explains why each loser lost: on origin and importance, on layer, on specificity or on order. Layer order is entered as a comma list, first is weakest, and unlayered styles beat every layer for normal declarations but lose to layered ones when both are !important.
Limits
This is a calculator, not a browser: it does not match selectors against your HTML, so it cannot tell you whether a rule applies to a given element at all. Inheritance, the style attribute's interaction with shadow DOM, @scope proximity and nested CSS (the & selector is counted as zero rather than resolved) are not modelled.
풀이 예시
A developer cannot make a button white. Three rules set its colour: #app .btn in the components layer gives navy, .text-white in the utilities layer gives white, and an unlayered button rule gives black, while the base layer has a button rule with color: red !important. The calculator shows #app .btn at (1,1,0) and .text-white at (0,1,0), but the cascade tab explains that specificity never gets a say: the !important rule in base wins over all normal declarations, and among the normal ones the unlayered button rule would beat both layered rules despite its (0,0,1) score. Removing the old !important and moving the button reset into the base layer makes .text-white win, because utilities is the last layer.
한눈에 보기
- 카테고리: 개발 및 데이터
- 브라우저에서 실행되며 가입도 업로드도 필요 없습니다.
- 입력한 정보는 기기에 머뭅니다.
- 영어로 제공됩니다.
- 콘텐츠 최종 검토일:
- 공식 출처: W3C Selectors Level 4 specificity and CSS Cascading and Inheritance Level 5
자주 묻는 질문
How is specificity written?
As three numbers (A, B, C): IDs, then classes, attributes and pseudo-classes, then types and pseudo-elements. The universal selector and combinators add nothing.
What does :where() count?
Always zero, whatever is inside. That makes it ideal for library defaults that users should be able to override with a single class.
What about :is(), :not() and :has()?
They are replaced by the score of their most specific argument. :is(#a, .b) counts as an ID even when the element matched through .b.
Does a higher specificity beat !important?
No. Importance is checked before specificity. An !important declaration wins over any normal declaration of the same origin, whatever the selectors.
How do cascade layers change things?
Layers are compared before specificity. For normal rules a later layer wins and unlayered rules win over all layers; for !important rules the order is reversed.
Is my stylesheet uploaded?
No. Parsing happens in your browser, and the draft stays in local storage on this device.
