Disabling Rules and Inline Comments
You'll learn how to temporarily turn off Stylelint rules when you have valid exceptions to the linting standards.
The Need for Exceptions
Even with great Stylelint rules in place, you'll occasionally encounter legitimate cases where breaking a rule makes sense—perhaps a vendor-required style, a necessary browser hack, or a one-off design exception. Rather than removing the rule entirely or fighting with false positives, Stylelint lets you disable specific rules for specific lines or blocks of code using special comments.
The Disable Comment Syntax
Stylelint recognizes inline comments that control rule enforcement:
/* stylelint-disable-next-line declaration-no-important */
.emergency-override {
color: red !important;
}
This disables the declaration-no-important rule for just the next line. You can also disable rules for entire blocks:
/* stylelint-disable selector-max-id */
#legacy-form input {
padding: 10px;
}
/* stylelint-enable selector-max-id */
To disable all rules temporarily (use sparingly):
/* stylelint-disable */
.messy-third-party-styles {
/* ... */
}
/* stylelint-enable */
When to Use Disable Comments
Use these comments thoughtfully—they're escape hatches, not everyday tools. Good reasons include integrating third-party CSS, working around browser bugs, or handling legacy code during refactoring. Always consider whether the rule itself needs adjusting before disabling it.
Key Takeaway: Stylelint disable comments give you surgical control to bypass rules for specific code without weakening your overall linting standards—use them intentionally for legitimate exceptions, not as shortcuts around good practices.