{"id":51133670,"url":"https://github.com/trananhtung/specificity","last_synced_at":"2026-06-28T18:00:41.130Z","repository":{"id":366615838,"uuid":"1276577070","full_name":"trananhtung/specificity","owner":"trananhtung","description":"Calculate the CSS specificity (a, b, c) of a selector — :is/:not/:has/:where aware. A Rust take on the specificity npm package. Zero deps, no_std.","archived":false,"fork":false,"pushed_at":"2026-06-22T14:47:44.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-06-22T16:26:46.555Z","etag":null,"topics":["cascade","css","no-std","rust","selector","specificity"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trananhtung.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-22T05:30:13.000Z","updated_at":"2026-06-22T14:50:03.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/trananhtung/specificity","commit_stats":null,"previous_names":["trananhtung/specificity"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/trananhtung/specificity","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trananhtung%2Fspecificity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trananhtung%2Fspecificity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trananhtung%2Fspecificity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trananhtung%2Fspecificity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trananhtung","download_url":"https://codeload.github.com/trananhtung/specificity/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trananhtung%2Fspecificity/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34780126,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-25T02:00:05.521Z","response_time":101,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cascade","css","no-std","rust","selector","specificity"],"created_at":"2026-06-25T15:01:44.833Z","updated_at":"2026-06-25T15:01:45.539Z","avatar_url":"https://github.com/trananhtung.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# specificity\n\n[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)\n\n[![Crates.io](https://img.shields.io/crates/v/specificity.svg)](https://crates.io/crates/specificity)\n[![Documentation](https://docs.rs/specificity/badge.svg)](https://docs.rs/specificity)\n[![CI](https://github.com/trananhtung/specificity/actions/workflows/ci.yml/badge.svg)](https://github.com/trananhtung/specificity/actions/workflows/ci.yml)\n[![License](https://img.shields.io/crates/l/specificity.svg)](#license)\n\n**Calculate the CSS specificity `(a, b, c)` of a selector** — `a` for ID selectors,\n`b` for classes/attributes/pseudo-classes, `c` for type selectors/pseudo-elements.\nModern selectors are handled per the\n[spec](https://www.w3.org/TR/selectors-4/#specificity-rules). The Rust counterpart of\nthe [`specificity`](https://www.npmjs.com/package/specificity) npm package. Zero\ndependencies and `#![no_std]`.\n\n```rust\nuse specificity::{specificity, Specificity};\n\nassert_eq!(specificity(\"#id .cls a\"), Specificity::new(1, 1, 1));\nassert_eq!(specificity(\":is(.a, #b)\"), Specificity::new(1, 0, 0)); // max of the args\nassert_eq!(specificity(\":where(.a)\"), Specificity::new(0, 0, 0));  // contributes nothing\n\n// Specificity is `Ord`, so selectors compare directly.\nassert!(specificity(\"#id\") \u003e specificity(\".a.b.c\"));\n```\n\n## Why specificity?\n\nCSS linters, cascade-analysis tools, devtools, and CSS-in-JS engines all need to\nknow how strongly a selector matches. The rules are small but full of corners\n(`:is`/`:not`/`:has` take the most specific argument, `:where` is free, `::part`\nignores its argument, namespaces and escapes don't fool the counter). Rust had this\nonly buried inside full CSS engines; this is the focused, dependency-free piece.\n\n```toml\n[dependencies]\nspecificity = \"0.1\"\n```\n\n## API\n\n| Item | Purpose |\n| --- | --- |\n| `specificity(selector)` | The `Specificity` of a single complex selector (max of a list) |\n| `specificity_list(list)` | One `Specificity` per comma-separated selector |\n| `Specificity { a, b, c }` | The components; implements `Ord` (a, then b, then c) and `Display` (`\"a,b,c\"`) |\n\n## Behavior\n\n- `a` = ID selectors; `b` = classes, attribute selectors, pseudo-classes;\n  `c` = type selectors and pseudo-elements. The universal `*` and combinators add\n  nothing.\n- `:is()`, `:not()`, `:has()` (and `:matches()`/`:-*-any()`) contribute the\n  specificity of their **most specific** argument; `:where()` contributes nothing.\n- `:nth-child()`/`:nth-last-child()` are pseudo-classes; an `… of S` argument adds\n  the most specific selector in `S`.\n- Pseudo-elements (`::before`, `::part(x)`, the legacy single-colon `:before`, …)\n  count as `c`, and their functional arguments are ignored.\n- Namespace prefixes (`svg|a`, `*|div`) and CSS escapes (`.foo\\.bar`) are parsed\n  correctly, and CSS `/* … */` comments are ignored.\n\n## Differences from the npm package\n\nWhere keeganstreet `specificity` diverges from the CSS spec, this crate follows the\nspec: `:matches()` / `:-*-any()` are treated as aliases of `:is()` (most specific\nargument, not a plain pseudo-class), and a namespaced universal such as `*|*`\ncontributes nothing. CSS Modules' `:global()` / `:local()` are supported, taking\ntheir argument's specificity.\n\n## Contributors ✨\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the [emoji key](https://allcontributors.org/docs/en/emoji-key) for how each contribution is recognized, and open a PR or issue to get involved.\n\nThanks goes to these wonderful people:\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/trananhtung\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/30992229?v=4?s=100\" width=\"100px;\" alt=\"Tung Tran\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTung Tran\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/trananhtung/specificity/commits?author=trananhtung\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#maintenance-trananhtung\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\n## License\n\nLicensed under either of [Apache-2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT) at\nyour option.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrananhtung%2Fspecificity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrananhtung%2Fspecificity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrananhtung%2Fspecificity/lists"}