Cascade layers: Control the CSS cascade with the @layer at-rule
Blog post from LogRocket
CSS, while relatively straightforward for developers to learn, can be challenging due to the cascade's complex nature, which often leads to issues in controlling styles. Traditional methodologies like inverted triangle CSS (ITCSS), object-oriented CSS (OOCSS), and block element modifier (BEM) have helped manage these challenges by maintaining low selector specificity, but they don't completely resolve conflicts between specificity and order of appearance. A new CSS feature, cascade layers, aims to address these issues by allowing developers to use the @layer at-rule to define and control the order of layers, effectively giving them more control over the cascade. This feature, part of the CSS cascading inheritance level 5 specifications, was initially proposed in 2019 and is now experimentally supported in major browsers like Chrome, Firefox, and Safari. Cascade layers prioritize styles based on their layer order rather than specificity or order of appearance, offering a solution to style rule conflicts and enhancing the management of CSS codebases. The article also touches upon the concept of unlayered styles, which take precedence over layered styles, and the future positioning of cascade layers in the CSS cascade algorithm, indicating a shift toward more intuitive style management in web development.