CSS: 1996 ‑ 2016 The internet was made for documents Global scope and the cascade made sense Denizens of the web have changed. Web development has changed.
Molding CSS to our needs SASS allowed common programming patterns such as variables, mixins (i.e. functions) and extensions. PostCSS made writing for multiple browsers more bearable CSS Modules mean the end of global namespaces. We're increasingly tacking on more solutions The core pain point of CSS is still the same:
Bad for maintainance? Bad at scale? Lack of scoping features → specificity wars Confusing behaviour of specificity, inheritance, cascade → specificity wars ...
This is not necessarily a bad thing, except when it is. Web owes its success to its accessibility. This accessibility is made possible with clear separation between content, style, and logic. This accessibility is compulsory, not a nice to have.
The cascade: 1. Select element; filter only rules that apply 2. Cascade order , 1. User agent 2. User agent !important 3. User 4. Author 5. CSS Animations (doesn't cascade) 6. Author !important 7. User !important 3. Specificity W3C MDN
The cascade: 1. Select element; filter only rules that apply 2. Cascade order 1. User agent 2. User 3. Author 4. CSS Animations (doesn't cascade) 3. Specificity
Atomic CSS BEM Great for lightning fast prototyping Fails to separate content and style (styling in markup) Lots of repetition as you apply 10, 20 classes to each element No styling in markup, no repeated class calls Repeats heavily in CSS as code is not reused across components Can encode DOM structure in CSS class names
Scoping our CSS Scoping in CSS is looking to be straightforward CSS4 Selector spec introduces :scope all: initial resets all CSS properties to their browser defaults
Hostile environments Real problem isn't so much our scope as it is shared scope You're probably familiar with not being able to control markup or CSS No amount of well defined scope or well crafted selectors will stop someone from directly targeting your element
The cascade: 1. User agent 2. User 3. Author 1 ‑ Framework 4. Author 2 ‑ Third party provider 5. Author 3 ‑ In‑house dev team 6. ... 7. CSS Animations (doesn't cascade)
What does it mean for us? The cascade is powerful. It's being ignored. Stop ignoring it. CSS4 Spec is exciting! ‑‑variables, :scope... play with it! SASS 3.1 supports first class functions BEM vs Atomic is like tabs vs spaces. Pros and cons. Try both out. Don't choose one blindly. Good interfacing between HTML/CSS/JS needed for separation of concerns