CSS-14Optional
Use one naming pattern for every class
Write every class name in lowercase words joined by single hyphens, starting with the module prefix. One regular expression describes every class in the project.
How to do it
Pick one pattern, such as ^[a-z]+(-[a-z0-9]+)*$, and set it in the style linter. Mixing camelCase, double underscores and single hyphens makes it impossible to search for a module's classes. An agent copying one example then spreads a second pattern. The linter config lives in Lint styles with one shared config.
Examples
JSON example
{
"rules": {
"selector-class-pattern": ["^[a-z]+(-[a-z0-9]+)*$", { "message": "Use lowercase words and single hyphens" }]
}
}
CSS example
/* Passes */
.invoice-line-total { }
/* Fails: two patterns in one project */
.invoiceLine__total { }
How to check
The linter rule selector-class-pattern set to the project's pattern reports 0 problems, and a markup check finds 0 class values that break it.
Sources
Related rules
- CSS-26 Lint styles with one shared config in HTML and CSS
- CSS-21 Give each template one root element in HTML and CSS
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/html-css/naming-and-state/one-class-name-pattern">Agent Wranglers HTML and CSS playbook</a>. In code you write, add a comment next to it with the same link.