Calculate specificity of a CSS Selector
Last release 1 years ago
02 Jun 2025
Ships unpredictably
gaps range from 9 days to 1.9 years
Some releases are documented
notes for 6 of 13 stable releases
Nothing withdrawn
no release was ever pulled
5 years old
25 releases · first in 2022
Release timeline
25 releases since 2022One column per quarter.
Releases
- 2.4.22 Jun 2025
Nothing published for this version
- 2.4.118 Feb 2025
Release notes
Open source →Changes & Additions
Maintenance release:
- ⬆️ Update dev dependencies
- 🎨 Fix lint errors
- 2.4.018 Feb 2025
Release notes
Open source →Changes & Additions
- ⬆️ Update css-tree to 3.0.0
- 🐛 Fix calculation of
:any/:-moz-any/:-webkit-anypseudo classes - 🐛 Do not crash when
nth-[last-]-child()has no children - ✨ Expose new
calculateForASTmethod - ✨ Add test for
&selector - ✨ Add tests to test standalone behavior
- ✨ Added benchmarks
Thanks to @bartveneman for contributing some of these changes and additions.
- 2.3.08 Apr 2023
Release notes
Open source →Changes & Additions
- ✨ Add view-transition specificity calculation
- 🐛 Do not throw when :is/:any/:matches do not contain children
- 🐛 Fix case sensitivity issue
Thanks to @bartveneman for contributing these changes and additions.
- 2.2.014 Dec 2022
Release notes
Open source →Changes & Additions
- ✨ Support
::slotted() - ✨ Support
:host()and:host-context()
- ✨ Support
- 2.1.01 Apr 2022
Release notes
Open source →Changes & Additions
- ✨ Also accept single CSSTree
SelectorASTs as input intocalculate
- ✨ Also accept single CSSTree
- 2.0.029 Mar 2022
Release notes
Open source →The main change in this next iteration of
@bramus/specificityis that everything is now exposed as part of a newly introducedSpecificityclass. The class represents specificity value, and also holds several static methods to calculate and work with specificities.Changes & Additions
- ✨ Introduce and use a
Specificityclass - ✨ Support SelectorLists
- ♻️ Import only
selector-parserfromcss-tree(reducing bundle size) - ✨ Expose new utility functions for comparing, sorting, and filtering (static or standalone)
- ✨ Add Type Definitions
- ✨ Expose the CLI script
- 🚑 Fix CJS build
Code Example
import Specificity from '@bramus/specificity'; // ✨ Calculate specificity for each Selector in the given Selector List const specificities = Specificity.calculate('header:where(#top) nav li:nth-child(2n), #doormat'); // 🚚 The values in the array are instances of the Specificity class const specificity = specificities[0]; // Instance of Specificity // 🛠 From an instance you can get the value in various formats specificity.value; // { a: 0, b: 1, c: 3 } specificity.a; // 0 specificity.b; // 1 specificity.c; // 3 specificity.toString(); // "(0,1,3)" specificity.toArray(); // [0, 1, 3] specificity.toObject(); // { a: 0, b: 1, c: 3 } // 💡 From an instance you can also get the selector (as a String) specificity.selectorString(); // "header:where(#top) nav li:nth-child(2n)" // 💻 These instances also play nice with JSON.stringify() console.log(JSON.stringify(specificity)); // { // "selector": 'header:where(#top) nav li:nth-child(2n)', // "asObject": { "a": 0, "b": 1, "c": 3 }, // "asArray": [0, 1, 3], // "asString": "(0,1,3)", // } // 🔀 Need to compare against another instance? That's possible! specificity.isEqualTo(specificities[1])); // false specificity.isGreaterThan(specificities[1])); // false specificity.isLessThan(specificities[1])); // true
- ✨ Introduce and use a
- 2.0.0-beta.1122 Mar 2022pre-release
Release notes
Open source →Changing since 2.0.0-beta.9
- REFACTOR: No longer expose
calculateor any of the utility methods from the main file. Instead, provide them as static methods onSpecificitywhich is now the default export. - REFACTOR: All utility methods that required one single array before, now work with an arbitrary number of arguments
- REFACTOR: Rename
ascending/descendingtosortAsc/sortDesc - REMOVE: No longer expose standalone
sort
- REFACTOR: No longer expose
- 2.0.0-beta.1011 Mar 2022pre-release
Nothing published for this version
- 2.0.0-beta.911 Mar 2022pre-release
Release notes
Open source →Changes since 2.0.0-beta.8
- ♻️ Rename Specificity.equals to Specificity.isEqualTo
- 2.0.0-beta.811 Mar 2022pre-release
Nothing published for this version
- 2.0.0-beta.710 Mar 2022pre-release
Nothing published for this version
- 2.0.0-beta.610 Mar 2022pre-release
Nothing published for this version
- 2.0.0-beta.510 Mar 2022pre-release
Nothing published for this version
- 2.0.0-beta.410 Mar 2022pre-release
Nothing published for this version
- 2.0.0-beta.39 Mar 2022pre-release
Nothing published for this version
- 2.0.0-beta.26 Mar 2022pre-release
Nothing published for this version
- 2.0.0-beta.127 Feb 2022pre-release
Nothing published for this version
- 2.0.0-beta.026 Feb 2022pre-release
Nothing published for this version
- 1.0.727 Feb 2022
Nothing published for this version
- 1.0.624 Feb 2022
Nothing published for this version
- 1.0.524 Feb 2022
Nothing published for this version
- 1.0.423 Feb 2022
Nothing published for this version
- 1.0.323 Feb 2022
Nothing published for this version
- 1.0.223 Feb 2022
Nothing published for this version