Home / Companies / LogRocket / Blog / Post Details
Content Deep Dive

How CSS @scope can replace BEM

Blog post from LogRocket

Post Details
Company
Date Published
Author
Andrew Evans
Word Count
2,074
Language
-
Hacker News Points
-
Summary

Frontend engineers often face challenges with CSS naming conventions, traditionally relying on the Block Element Modifier (BEM) method for organizing styles. The introduction of the @scope feature in Chrome aims to enhance this by enabling block-level scoping of styles within stylesheets, offering improved control over the CSS cascade and simplifying style management. This feature, expected with Chrome 118, allows for more concise style definitions compared to BEM, as seen in refactoring examples using React, which highlight cleaner and more manageable code. While @scope has the potential to streamline front-end styling significantly, it requires enabling experimental web features in Chrome, as full browser support is still pending. The feature not only reduces the complexity of CSS files but also mitigates the unintended side effects of the CSS cascade, potentially transforming the way developers approach styling in large projects.