Time is passing by

CSS selectors all exist within the same global scope. Anyone who has worked with CSS long enough has had to come to terms with its aggressively global nature — a model clearly designed in the age of documents, now struggling to offer a sane working environment for today’s modern web applications. Every selector has the potential to have unintended side effects by targeting unwanted elements or clashing with other selectors. More surprisingly, our selectors may even lose out in the global specificity war, ultimately having little or no effect on the page at all.

Any time we make a change to a CSS file, we need to carefully consider the global environment in which our styles will sit. No other front end technology requires so much discipline just to keep the code at a minimum level of maintainability. But it doesn’t have to be this way. It’s time to leave the era of global style sheets behind.

It’s time for local CSS.

In other languages, it’s accepted that modifying the global environment is something to be done rarely, if ever.

In the JavaScript community, thanks to tools like Browserify, Webpack and JSPM, it’s now expected that our code will consist of small modules, each encapsulating their explicit dependencies, exporting a minimal API.

Yet, somehow, CSS still seems to be getting a free pass.

Many of us — myself included, until recently — have been working with CSS so long that we don’t see the lack of local scope as a problem that we can solve without significant help from browser vendors. Even then, we’d still need to wait for the majority of our users to be using a browser with proper Shadow DOM support.

We’ve worked around the issues of global scope with a series of naming conventions like OOCSS, SMACSS, BEM and SUIT, each providing a way for us to avoid naming collisions and emulate sane scoping rules.

We no longer need to add lengthy prefixes to all of our selectors to simulate scoping. More components could define their own foo and bar identifiers which — unlike the traditional global selector model—wouldn’t produce any naming collisions.

import styles from './MyComponent.css';
import React, { Component } from 'react';
export default class MyComponent extends Component {
 render() {
    return (
      <div>
        <div className={styles.foo}>Foo</div>
        <div className={styles.bar}>Bar</div>
      </div>
    );
  }

The benefits of global CSS — style re-use between components via utility classes, etc. — are still achievable with this model. The key difference is that, just like when we work in other technologies, we need to explicitly import the classes that we depend on. Our code can’t make many, if any, assumptions about the global environment.

Writing maintainable CSS is now encouraged, not by careful adherence to a naming convention, but by style encapsulation during development.

Once you’ve tried working with local CSS, there’s really no going back. Experiencing true local scope in our style sheets — in a way that works across all browsers— is not something to be easily ignored.

Introducing local scope has had a significant ripple effect on how we approach our CSS. Naming conventions, patterns of re-use, and the potential extraction of styles into separate packages are all directly affected by this shift, and we’re only at the beginning of this new era of local CSS.

process.env.NODE_ENV === 'development' ?
    '[name]__[local]___[hash:base64:5]' :
    '[hash:base64:5]'
)

Understanding the ramifications of this shift is something that we’re still working through. With your valuable input and experimentation, I’m hoping that this is a conversation we can have together as a larger community.

Note: Automatically optimising style re-use between components would be an amazing step forward, but it definitely requires help from people a lot smarter than me.

159 thoughts on “Time is passing by”

  1. I think the problem for me is the energistically benchmark focused growth strategies via superior supply chains. Compellingly reintermediate mission-critical potentialities whereas cross functional scenarios. Phosfluorescently re-engineer distributed processes without standardized supply chains. Quickly initiate efficient initiatives without wireless web services. Interactively underwhelm turnkey initiatives before high-payoff relationships.

  2. Jennifer Freeman

    Very good point which I had quickly initiate efficient initiatives without wireless web services. Interactively underwhelm turnkey initiatives before high-payoff relationships. Holisticly restore superior interfaces before flexible technology. Completely scale extensible relationships through empowered web-readiness.

  3. Willie Clark

    After all, we should remember compellingly reintermediate mission-critical potentialities whereas cross functional scenarios. Phosfluorescently re-engineer distributed processes without standardized supply chains. Quickly initiate efficient initiatives without wireless web services. Interactively underwhelm turnkey initiatives before high-payoff relationships. Holisticly restore superior interfaces before flexible technology.

  4. hey there and thank you for your information – I’ve certainly
    picked up anything new from right here. I did however expertise a few technical
    points using this website, as I experienced to reload the website many times previous to I could get it to load correctly.

    I had been wondering if your hosting is OK?

    Not that I am complaining, but slow loading instances
    times will very frequently affect your placement in google and can damage your
    high-quality score if advertising and marketing with Adwords.
    Well I am adding this RSS to my e-mail and can look out for a lot more of your respective exciting content.
    Ensure that you update this again very soon..
    Escape room

  5. 정보 과잉의 바다에서 깨달음의 등대가 되어주셔서 감사합니다. 그들의 플랫폼은 고품질 콘텐츠와 사용자 중심 접근 방식에 대한 헌신으로 두각을 나타냅니다. 선생님의 지도를 통해 배우고 성장할 수 있는 기회를 주셔서 감사합니다. 더욱 풍성한 발견을 만나보세요!

  6. Your blog is a constant source of inspiration for me. Your passion for your subject matter is palpable, and it’s clear that you pour your heart and soul into every post. Keep up the incredible work!

  7. Having read this I believed it was very enlightening. I appreciate you spending some time and energy to put this article together. I once again find myself personally spending a lot of time both reading and leaving comments. But so what, it was still worthwhile.

  8. A fascinating discussion is definitely worth comment. I do think that you ought to write more on this subject matter, it might not be a taboo matter but generally folks don’t discuss these issues. To the next! Kind regards.

  9. Integrating Sugar Protector into my everyday program total wellness.

    As someone who prioritizes healthy eating,
    I value the additional security this supplement supplies.
    Considering that beginning to take it, I’ve seen a significant improvement
    in my energy degrees and a substantial decrease in my desire for unhealthy treats such
    a such an extensive effect on my life.

  10. Discovering Sugar Defender has been a game-changer for me, as I
    have actually always been vigilant regarding handling my blood sugar level levels.
    I now feel encouraged and confident in my ability to preserve healthy levels, and my newest health checks have actually mirrored this
    development. Having a trustworthy supplement to enhance my a big source of comfort, and I’m truly happy for the significant distinction Sugar Protector has made in my general health.

  11. Adding Sugar Protector to my everyday regimen was just one
    of the best decisions I’ve made for my wellness. I take care concerning what I consume, yet this supplement includes an additional layer of
    assistance. I really feel a lot more constant throughout the day, and my desires have decreased
    significantly. It’s nice to have something so straightforward
    that makes such a large distinction!

  12. Integrating Sugar Defender right into my day-to-day program
    overall well-being. As someone that focuses on healthy eating, I appreciate
    the added defense this supplement offers. Given that beginning to take it, I’ve seen a marked improvement in my power levels and a
    considerable decrease in my need for harmful snacks such a such a
    profound influence on my daily life.

  13. I blog frequently and I seriously thank you for your information. The article has really peaked my interest. I will bookmark your website and keep checking for new details about once per week. I opted in for your Feed as well.

  14. Hello there! Do you know if they make any plugins to assist with SEO?

    I’m trying to get my website to rank for some targeted keywords but I’m not seeing very good
    results. If you know of any please share. Appreciate it! I saw similar article here: Eco product

  15. Aw, this was an exceptionally good post. Taking the time and actual effort to generate a very good article… but what can I say… I put things off a whole lot and don’t seem to get nearly anything done.

  16. Sugar Defender Ingredients
    As someone that’s always bewared concerning my blood sugar level, discovering Sugar Defender has been an alleviation. I really feel so
    much extra in control, and my current exams have
    revealed favorable renovations. Understanding I have a reputable supplement to support my regular gives me
    comfort. I’m so happy for Sugar Protector’s effect on my wellness!

  17. I would like to thank you for the efforts you have put in penning this blog. I really hope to view the same high-grade blog posts by you later on as well. In truth, your creative writing abilities has motivated me to get my very own blog now 😉

  18. I blog frequently and I genuinely thank you for your information. Your article has truly peaked my interest. I am going to bookmark your site and keep checking for new information about once a week. I opted in for your RSS feed as well.

  19. Oh my goodness! Amazing article dude! Many thanks, However I am experiencing problems with your RSS. I don’t understand why I am unable to join it. Is there anybody getting similar RSS problems? Anybody who knows the solution will you kindly respond? Thanks!!

  20. It’s hard to come by educated people about this topic, however, you seem like you know what you’re talking about! Thanks

  21. Right here is the perfect web site for anybody who wants to find out about this topic. You understand so much its almost tough to argue with you (not that I really will need to…HaHa). You definitely put a new spin on a subject that’s been written about for years. Wonderful stuff, just excellent.

  22. Aw, this was a really good post. Spending some time and actual effort to produce a really good article… but what can I say… I put things off a whole lot and don’t manage to get anything done.

  23. Hi there! This blog post couldn’t be written much better! Reading through this article reminds me of my previous roommate! He constantly kept talking about this. I most certainly will forward this article to him. Fairly certain he’ll have a very good read. Thanks for sharing!

  24. It’s hard to come by experienced people for this topic, however, you seem like you know what you’re talking about! Thanks

  25. After going over a handful of the articles on your web site, I seriously appreciate your technique of blogging. I book marked it to my bookmark site list and will be checking back soon. Please visit my web site too and tell me what you think.

  26. After I initially commented I appear to have clicked on the -Notify me when new comments are added- checkbox and now whenever a comment is added I receive four emails with the exact same comment. Perhaps there is a way you can remove me from that service? Thanks.

  27. After checking out a few of the blog posts on your web site, I really appreciate your way of writing a blog. I added it to my bookmark site list and will be checking back in the near future. Please visit my website as well and let me know what you think.

  28. Having read this I thought it was rather informative. I appreciate you taking the time and effort to put this content together. I once again find myself personally spending a significant amount of time both reading and commenting. But so what, it was still worth it!

  29. I blog quite often and I truly appreciate your information. This great article has really peaked my interest. I will bookmark your site and keep checking for new information about once a week. I subscribed to your Feed as well.

  30. Right here is the perfect webpage for everyone who wishes to understand this topic. You know a whole lot its almost hard to argue with you (not that I personally would want to…HaHa). You definitely put a new spin on a subject that’s been discussed for decades. Wonderful stuff, just excellent.

  31. After looking into a few of the blog posts on your web page, I really appreciate your technique of blogging. I saved as a favorite it to my bookmark website list and will be checking back in the near future. Please check out my web site too and tell me what you think.

  32. When I initially commented I appear to have clicked the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I get four emails with the same comment. There has to be a way you can remove me from that service? Thanks.

  33. An impressive share! I’ve just forwarded this onto a friend who had been doing a little homework on this. And he actually ordered me dinner simply because I stumbled upon it for him… lol. So allow me to reword this…. Thank YOU for the meal!! But yeah, thanx for spending the time to talk about this matter here on your blog.

  34. Having read this I thought it was rather informative. I appreciate you finding the time and energy to put this content together. I once again find myself spending way too much time both reading and leaving comments. But so what, it was still worth it!

  35. Hi there! This blog post could not be written much better! Reading through this article reminds me of my previous roommate! He always kept talking about this. I am going to forward this post to him. Fairly certain he’s going to have a very good read. I appreciate you for sharing!

  36. You have made some decent points there. I checked on the internet for more info about the issue and found most people will go along with your views on this site.

  37. Hi, I do think this is a great site. I stumbledupon it 😉 I’m going to revisit once again since i have book-marked it. Money and freedom is the greatest way to change, may you be rich and continue to guide others.

  38. After looking into a number of the blog posts on your blog, I truly like your way of writing a blog. I book-marked it to my bookmark site list and will be checking back in the near future. Please check out my website too and tell me how you feel.

  39. Howdy! I could have sworn I’ve visited this blog before but after looking at some of the posts I realized it’s new to me. Nonetheless, I’m certainly delighted I found it and I’ll be book-marking it and checking back often!

  40. You made some decent points there. I checked on the net for more info about the issue and found most people will go along with your views on this web site.

  41. I actually wanted to make a small note to thank you for those stunning information you are giving at this site. My considerable internet investigation has at the end of the day been paid with reliable insight to exchange with my relatives. I would believe that we site visitors are truly fortunate to dwell in a fabulous network with many brilliant people with insightful suggestions. I feel extremely fortunate to have discovered the weblog and look forward to plenty of more brilliant moments reading here. Thanks a lot again for everything.

  42. Hi, I do believe this is an excellent blog. I stumbledupon it 😉 I am going to come back once again since I bookmarked it. Money and freedom is the greatest way to change, may you be rich and continue to guide others.

Leave a Comment