CSS is global by nature. Given the name, style sheets are intended to cascade and a single CSS rule could apply to multiple elements on your site. This is a powerful feature of CSS that can allow you to create consistent styling throughout your site with small amounts of code. But increasingly there are cases where front end developers want to instead scope their styles to a specific component and ensure that component styles are consistent and don’t impact other areas of the site.
Starting from the perspective of CSS only approaches we’ll look at:
A brief review of CSS Inheritance and the Cascade
Scoping with BEM and other naming methodologies
Atomic or Functional CSS
Scoped styles using CSS Modules
React CSS in JS libraries including Styled Components and Emotion
Component styling in Angular and Vue
Finally, we’ll wrap up by looking at a few ways that global and scoped CSS can be used together effectively.
Ways to share styles between ’traditional’ styling and CSS in JS approaches.
Lead Front End Developer
Brian is a versatile developer with experience building complex, interactive web applications in support of large-scale localized sites. Recently he has focused his efforts on evolving Drupal front-end development practices, decoupled Drupal, and style guide development techniques and has spoken on the topic at various Drupal events. Brian is a Drupal 7 and Drupal 8 Acquia Certified Grand Master and loves all things Nintendo.