avoid-using-id-selectors-for-styling
Installation
SKILL.md
Summary
Use classes (.classname) for styling. Do not use IDs (#idname) for CSS rules. Reserve IDs for JavaScript hooks, anchor links, and accessibility attributes (ARIA).
Rationale
- Specificity: IDs have vastly higher specificity than classes. You cannot override
#header { color: red }with.header-dark { color: blue }unless you chain many classes or use!important. - Reusability: IDs are unique by definition. You cannot reuse
#submit-buttonon a second button, whereas.submit-buttonis reusable.
Guidance
- Refactor: Convert
#headerto.header. - Hooks: It is fine to have
<div id="app" class="app">. Style.app, target#appin JS.
Examples
Bad
#sidebar {
width: 300px;
}