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.
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.
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.
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.
Hey there! I just wish to offer you a big thumbs up for your excellent info you’ve got here on this post.
I will be coming back to your site for more soon.
This excellent website truly has all of the information I needed concerning this subject and didn’t know who to ask.
Excellent info it is actually. I have been awaiting for this tips. Atlante Peterus Sadoc
If you are in charge with picking out the uniforms, choose colors that really stand out. Colly Brandon Melissa
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. Mara Shep Yorgos
very nice put up, i actually love this web site, carry on it Carmina Kendell Rem
This is my first time pay a quick visit at here and i am truly impressed to read everthing at alone place. Arliene Greg Antoinetta Brynn Rafaello Kristos
After I initially left a comment I seem to have clicked the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I get 4 emails with the exact same comment. Perhaps there is a way you are able to remove me from that service? Many thanks! Bili Richart Barbie
I think it is a fluent sharing, I will recommend your site to my friends Marti Maxy Ed
Hi! I simply would like to give you a big thumbs up for the excellent information you have got right here on this post. I will be coming back to your web site for more soon. Christin Van Barger
If you wish for to increase your knowledge simply keep visiting this web site and be updated with the newest information posted here. Brittani Shayne Catha
This article is really a nice one it assists new web people, who are wishing for blogging.| Florri Desmond Rosenstein
Hello there. I discovered your blog via Google whilst looking for a comparable topic, your site got here up. It looks good. I have bookmarked it in my google bookmarks to come back then. Calley Spence Beatriz
Cheap school essay ghostwriting site for college . Malina Sammy Kerwin
I am really thankful to the owner of this web page who has shared this impressive post at at this place. Camel Amos Charlene
Having read this I believed it was extremely informative. I appreciate you taking the time and effort to put this informative article together. I once again find myself personally spending way too much time both reading and leaving comments. But so what, it was still worthwhile. Lilla Dirk Ashien
Hello ! Effectivement merci pour ces deux conseils ! Fancie Garwin Fan
Nice answers in return of this difficulty with real arguments and describing everything on the topic of that. Austina Hershel Benoite
Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you can do with a few pics to drive the message home a little bit, but instead of that, this is magnificent blog. A great read. I will definitely be back. Corina Gearalt Amand
Draga Otilia, dragi colegi implicati in conferinta ERMAS, Julissa Steffen Adal
There is definately a great deal to find out about this topic. I really like all the points you made. Sheryl Isak Florette
This coin is the best, a cousin recommended this cryptocurrency and I have had many bad experiences with fraudulent cryptocurrencies, could one tell me how safe is this currency? I have read that it is very safe but I would like someone to confirm that. Theda Care Sherill
I have been browsing online more than three hours today, yet I never found any interesting article like yours. Sadie Dalton Fritze
Hi there outstanding website! Does running a blog such as this take a lot of work? I have absolutely no knowledge of programming but I was hoping to start my own blog soon. Anyways, should you have any ideas or techniques for new blog owners please share. I understand this is off topic nevertheless I simply needed to ask. Thank you! Marja Delmore Ballou
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam blandit sem vel neque iaculis, vitae tempus lacus pellentesque. Nullam sed est vel massa laoreet varius. Sed euismod arcu ante, ac lacinia nunc venenatis eget. Sed bibendum, turpis vitae dapibus venenatis, urna ex blandit felis, eu faucibus mi sapien non velit. Gwenora Gram Louisa
I blog frequently and I really thank you for your information. The article has really peaked my interest. I am going to book mark your site and keep checking for new details about once per week. I opted in for your RSS feed as well. Nisse Sol Ammann
iya nih saya di Malang sering ngisi2 buat dapet bantuan untuk UMKM. Membaca syarat-syaratnya jadi sedikit banyak tahu. Tapi sampe skg gak diapprove2. eeh malah curcol ya hehe Eileen Tallie Delwin
Flying object also have wromg with my new android device. I transfer from my nokia device, old c.mas not yet 3 starred, but flying object on that episode showing star. Ali Vachel Marylinda
Hi there. I found your site via Google while searching for a related topic, your website came up. It looks good. I have bookmarked it in my google bookmarks to visit then. Laural Jule Kassandra
cialis coupons canadian international pharmacy association cialis coupon Belia Vito Lubba
I have been surfing online more than 3 hours today, yet I never found any interesting article like yours. Jojo Sholom Hussein
Hello. This article was really remarkable, especially because I was browsing for thoughts on this matter last Monday. Krissie Wilhelm Ash
Normally I do not read article on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Thanks, very nice article. Pavla Lezley Sande
Waoh! Good to hear about the church. May God continue to honor His words in your life. Trudy Errick Launce
I was pretty pleased to find this page. I want to to thank you for your time just for this fantastic read!! I definitely loved every part of it and I have you book-marked to see new things on your web site. Marena Miltie Vito
I conceive you have observed some very interesting points , regards for the post. Gilli Hugh Navarro
doresc acest cort pe dimensiunile L 13-15m ;l 8-10m ;h 3-4m Patrizia Victor Kingsbury
I all the time emailed this weblog post page to all my contacts, as if like to read it next my contacts will too. Ibbie Glenden Jaela
Knowledge wants to be free, just like these articles! Aigneis Lambert Xaviera
Thanks for sharing your thoughts on online tutors. Regards Calypso Kendricks Amabel
Thank you for the sensible critique. Me and my neighbor were just preparing to do a little research about this. Lian Jayson Bellaude
You have brought up a very great points , thankyou for the post. Letisha Osbourne Salem
Hi Sajib, Happy to read your article. Your suggestions is really good for home office. Best wishes. Rhea Monroe Wappes
Hey there. I discovered your site by the use of Google even as looking for a related topic, your website got here up. It looks great. I have bookmarked it in my google bookmarks to visit then. Almire Axel Alodi
As soon as I discovered this web site I went on reddit to share some of the love with them. Michaella Brade Johnstone
Plan on taking CPP at 65 since my company pension plan is bridged till 65. Gloriana Milt Rawdin
Of course, what a magnificent site and informative posts, I definitely will bookmark your blog. Best Regards! Kathrine Giuseppe Burnley
Nullam convallis, dolor et volutpat gravida, neque ligula malesuada ligula, mollis blandit purus lacus vitae ex. Aliquam a tortor nibh. Mauris nec diam ex. Susan Geordie Sachs
Sakurapoker juga memberikan kemudahan bertransaksi seperti deposit 24 jam semua bank seperti bca, bni, mandiri, bri dan cimb. Semua transaksi akan diproses tanpa adanya jam offline, transaksi tidak akan diproses jika posisi bank sedang gangguan. Corabella Pavel Armillda
Hi there, just became aware of your blog through Google, and found that it is really informative. I am gonna watch out for brussels. I will be grateful if you continue this in future. Lots of people will be benefited from your writing. Cheers!| June Rowan Monto
Yes! Finally something about verify google business. Celestina Elmore Merrie
Its like you learn my mind! You appear to know so much about this, like you wrote the ebook in it or something. Remy Gawain Booker
The best roofing contractor in Aurora, IL for roof repair, roof replacement, roof inspection and more. Janis Wit Jacquet
Awesome post. I am a normal visitor of your web site and appreciate you taking the time to maintain the nice site. I will be a regular visitor for a really long time. Inessa Dougie Narcis
I was pretty pleased to discover this website. I need to to thank you for ones time for this fantastic read!! I definitely loved every little bit of it and I have you saved to fav to check out new things in your site. Amalie Ase Jae
Wow, great article post. Thanks Again. Really Great. Juliane Thibaut Sapphera Kirsti Harlan Giacomo
Thank you ever so for you article post. Really looking forward to read more. Much obliged. Brandice Colan Rogers
One happy girl, the result of placid caring parents who give her lots of love. Kirsteni Derrick Liddie
I enjoy you because of your entire work on this site. Gloria takes pleasure in going through research and it is easy to see why. We hear all concerning the compelling means you make both interesting and useful tactics by means of your blog and even foster participation from others on that concern while our own daughter has always been starting to learn a lot of things. Take advantage of the remaining portion of the year. You are conducting a useful job. Mil Dewie Hampton
Thank you for every one of your effort on this web site. My mom take interest in going through internet research and it is easy to see why. Most of us hear all regarding the powerful way you create priceless techniques via the web site and as well as invigorate participation from some others on the area and our own daughter is in fact understanding so much. Enjoy the remaining portion of the year. You have been conducting a wonderful job. Xylina Dud Jeanine
Definitely, what a great blog and instructive posts, I will bookmark your site. Best Regards! Carine Hamish Brandt
I was studying some of your content on this site and I believe this internet site is really instructive! Keep putting up. Sabina Allin Ortiz
A motivating discussion is definitely worth comment. I do believe that you should write more about this topic, it might not be a taboo matter but typically people do not discuss such topics. To the next! All the best!!| Tammara Mayer Lois
I think this is one of the most important info for me. And i am glad reading your article. But wanna remark on some general things, The website style is wonderful, the articles is really excellent : D. Good job, cheers Lindsay Nevile Marchese
Pretty! This has been an incredibly wonderful post. Thanks for providing these details. Perry Carny Zacherie
Positive site, where did u come up with the information on this posting? Viviana Isak Woody
Beautiful land of Sicily! Short but nice and interesting guide. Deloria Ferguson Eben
You ought to take part in a contest for one of the most useful blogs on the web. I am going to highly recommend this website! Leontyne Torey Chaney
This article provides clear idea for the new people of blogging, that in fact how to do blogging.| Sibella Thorsten Silvano
I bow down humbly in the presence of such greatness. Gates Lauritz Kingsley
A round of applause for your post. Much thanks again. Great. Verena Jeffrey Jadd Brigitta Benson Stefanie
Thank you, Dr. Woods, for these inspiring words. I love the metaphors of all the pathways/bridges/tunnels we, as instructors, can be and can create for our students in their journeys to leading meaningful change in the world. I love and trust my students and am excited to follow their lead! Katey Callean Sup
Hi there it’s me, I am also visiting this website regularly, this web site is actually nice and the users are actually sharing pleasant thoughts.| Loree Jourdain Bastian
Excellent post. Keep posting such kind of info on your page. Emogene Sutherland Fadiman
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. Ernaline Braden Gaelan
With havin so much content do you ever run into any problems of plagorism or copyright infringement? Gertrud Linn Borszcz