prefer-data-theme-color-mode
Prefer Docusaurus data-theme selectors over legacy .theme-dark and .theme-light classes.
Targeted pattern scopeโ
This rule targets selector usage of legacy Docusaurus color-mode classes:
.theme-dark.theme-light
What this rule reportsโ
This rule reports selectors that use legacy theme classes instead of Docusaurus data-theme attribute selectors.
Why this rule existsโ
Modern Docusaurus documents color-mode styling through the data-theme attribute on the root HTML element.
Using the attribute selector keeps styles aligned with the current platform contract and avoids carrying older selector conventions forward.
โ Incorrectโ
.theme-dark .navbar {
color: white;
}
โ Correctโ
[data-theme="dark"] .navbar {
color: white;
}
Behavior and migration notesโ
- This rule autofixes
.theme-darkto[data-theme='dark']. - It autofixes
.theme-lightto[data-theme='light']. - The fixer only rewrites the selector token itself; it does not restructure the surrounding rule.
Additional examplesโ
โ Correct โ light mode selectorโ
[data-theme="light"] .footer {
color: black;
}
Stylelint config exampleโ
import { docusaurusPluginConfigs } from "stylelint-plugin-docusaurus";
export default {
...docusaurusPluginConfigs["docusaurus-recommended"],
rules: {
...docusaurusPluginConfigs["docusaurus-recommended"].rules,
"docusaurus/prefer-data-theme-color-mode": true,
},
};
When not to use itโ
Disable this rule if your codebase intentionally preserves legacy theme class selectors for backward-compatibility with an older Docusaurus integration layer.
Package documentationโ
Docusaurus package documentation:
Rule catalog ID: R003