10303 shaares
289 private links
289 private links
To keep the code maintainable, keep the css specificity as low as possible.
BEM falls short: class names can get really long; reusability might not be prioritized; and things must be named.
Another case is to use utility classes (atomic css) to avoid css specificity.
A new approach is with cascade layers.
Anyways, Cascade Layers (@layers) groups styles and declares what order the groups should be, regardless of the specificity scores of those rules.
Each has a sweet spot:
- BEM for clear design system that needs to be consistent; team with different philosophies; styles are less likely to leak between components.
- utility classes: build fast, like prototypes or MVPs and component based JS framework
- cascade layers: legacy codebases where you need full specificity control; integrate third party libraries or styles from other sources; working on a large, complex application or projects with long-term maintenance
How they can work together?
The cascade layers can be seen as an orchestrator: one layer for components (BEM); one layer for utilities (utility classes)