prefer-stable-docusaurus-theme-class-names
Prefer documented stable Docusaurus theme class names over attribute-selector fallbacks for known theme components.
Targeted pattern scopeโ
This rule targets attribute selectors such as [class*='...'] and [class^='...'] when Docusaurus already exposes a documented stable theme class on the same element.
The initial curated mappings in this rule cover:
codeBlockContainerโ.theme-code-blockannouncementBarโ.theme-announcement-barbackToTopButtonโ.theme-back-to-top-buttontocMobileโ.theme-doc-toc-mobile
What this rule reportsโ
This rule reports resilient attribute-selector fallbacks like [class*='codeBlockContainer'] when Docusaurus already provides a stable theme class that should be targeted instead.
Why this rule existsโ
Docusaurus documents stable theme class names as the maintainable customization surface for global CSS.
Attribute selectors that target CSS-module implementation details are sometimes more resilient than exact hashed class names, but they are still a fallback. When a stable theme class already exists, that stable class is the better long-term contract.
โ Incorrectโ
[class*="codeBlockContainer"] {
border-radius: 8px;
}
โ Correctโ
.theme-code-block {
border-radius: 8px;
}
Behavior and migration notesโ
- This rule is intentionally curated. It only reports attribute selectors for known Docusaurus component mappings where a stable theme class is documented on the same element.
- It does not autofix because replacing an attribute selector with a stable theme class can change selector specificity and may need human review.
- This rule complements
no-unstable-docusaurus-generated-class-selectors: that rule catches exact hashed class selectors, while this rule catches fallback attribute selectors when a better stable class already exists.
Additional examplesโ
โ Correct โ stable announcement bar classโ
.theme-announcement-bar {
padding-block: 1rem;
}
โ Correct โ stable mobile table-of-contents classโ
.theme-doc-toc-mobile {
margin-top: 1rem;
}
โ Allowed โ no known stable equivalent in the rule map yetโ
[class*="announcementBarContent"] {
max-width: 60rem;
}
Stylelint config exampleโ
import { docusaurusPluginConfigs } from "stylelint-plugin-docusaurus";
export default {
...docusaurusPluginConfigs["docusaurus-all"],
rules: {
...docusaurusPluginConfigs["docusaurus-all"].rules,
"docusaurus/prefer-stable-docusaurus-theme-class-names": true,
},
};
When not to use itโ
Disable this rule if your project intentionally relies on attribute selectors for these known Docusaurus theme internals and you accept that choice over the documented stable class surface.
Package documentationโ
Docusaurus package documentation:
Rule catalog ID: R007