How To Use Nesting In Plain CSS

Sdílet
Vložit
  • čas přidán 13. 06. 2024
  • I cannot believe it is finally happening. CSS is getting native support for nesting and it is everything I ever could have asked for. In this video I explain how you can start using nesting today as well as all the edge cases you need to be aware of if you start using nesting yourself.
    📚 Materials/References:
    CSS Specificity Video: • Learn CSS Specificity ...
    CSS Specificity Article: blog.webdevsimplified.com/202...
    🌎 Find Me Here:
    My Blog: blog.webdevsimplified.com
    My Courses: courses.webdevsimplified.com
    Patreon: / webdevsimplified
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/WebDevSimplified
    CodePen: codepen.io/WebDevSimplified
    ⏱️ Timestamps:
    00:00 - Introduction
    00:24 - Setup
    01:30 - Nesting Basics
    03:52 - Nested Media Queries
    04:53 - Nesting Specificity
    08:10 - @nest Keyword
    09:54 - Nesting Ordering Gotcha
    #CSS #WDS #CSSNesting

Komentáře • 137

  • @jon8236
    @jon8236 Před rokem +138

    Why is the official css syntax always more complicated than the scss equivalent when they have scss as an example on how to do it lol

    • @felix_xb
      @felix_xb Před rokem

      Because they're morons that never actually wrote css. Same for js spec ones. Typically "hotshot" super engineers that don't care for the language and have wierd nonsense biases from whatever it is they like as a hobby.

    • @rutgerhoutdijk3547
      @rutgerhoutdijk3547 Před rokem +21

      propably because it takes years to create a global web standard, then it takes months to years before browsers support it.
      However imho there is no excuse for not having nesting in the standard.

    • @jon8236
      @jon8236 Před rokem +18

      I’m not saying adoption of features, I mean the actual syntax. Why have the ‘&’ before nested selectors for example.

    • @jiraibozo
      @jiraibozo Před rokem +5

      you need the & because if not it might be ambiguous, like if you write color:hover the parser will see that you are setting the color property

    • @aesthet1k_
      @aesthet1k_ Před rokem +10

      @@jiraibozo But the & isn't a browser parser issue in this context, it's a spec issue. This awkward syntax is being written into the spec, despite this problem having already been solved by SCSS's nesting syntax. The native CSS nesting syntax just feels clunky in contrast, and frankly just seems different for the sake of being different.

  • @diamondkingx6281
    @diamondkingx6281 Před rokem +10

    You got me in the first half!

  • @mrleblanc
    @mrleblanc Před rokem +4

    This is so convoluted, never gonna ditch SCSS

  • @casualgamer9025
    @casualgamer9025 Před rokem

    Thanks for the update! This is the first time I have heard of this upcoming thing that the browser will finally support in the future.

  • @jayasood3205
    @jayasood3205 Před rokem

    Great video! Nice and in depth as always!

  • @LeeCorbin
    @LeeCorbin Před rokem +3

    Awesome channel, I've learned loads. 👍🏿"Cutting edge" you say... I can't wait for your video on the updated 'Select' element (currently in experimental development).

  • @pouriyanourouznejad7090
    @pouriyanourouznejad7090 Před rokem +1

    That was completely new for me!
    I'll try it!
    A BIG thanks from me 💜

  • @nove1398
    @nove1398 Před rokem +1

    Finally, i been waiting on this.

  • @pxlbltz
    @pxlbltz Před rokem +43

    I guess I will stay with SCSS even when this feature gets rolled out 😉

    • @nothingisreal6345
      @nothingisreal6345 Před rokem

      Why not simply use SCSS instead of CSS...

    • @timoernst
      @timoernst Před rokem +3

      @@nothingisreal6345 Because in large projects transpiling/compiling with sass can take a very long time. If you go pure css, you won’t need the transpilation step. Only minification for production shipping would be required. This is great because it speeds up the dev process significantly.

    • @sebastiangudino9377
      @sebastiangudino9377 Před rokem +2

      @@timoernst To be fair in large projects you probably would be using a componen based design system with its own scoped styles tho. So the use of SCSS (In regards to this particular feature!) Is kinda irrelevant

    • @pxlbltz
      @pxlbltz Před rokem +2

      In my personal experience, compilation and minification has always been really fast even in larger projects and because of that I haven't written pure CSS for years now. I've recently come to like Tailwind (after I wasn't a big fan of that approach before) so I think I will use that for the next larger projects, I guess.

    • @sebastiangudino9377
      @sebastiangudino9377 Před rokem +2

      @@pxlbltz Tailwind is a godsend in production. It might no be pretty, but it gets things done extremely fast. While also playing very well with design tools like Figma. Very nonstandard approach, but boy does it work marvelously in practice, specially with something like NextJS

  • @engelshernandez5898
    @engelshernandez5898 Před rokem

    Really good. Thanks!

  • @khaled-dev
    @khaled-dev Před rokem

    bro looked really excited :D

  • @beinyourguard
    @beinyourguard Před rokem +9

    tbh they should've just used the SCSS syntax. it's not worth to switch from it imo.

    • @LarrystoneTech
      @LarrystoneTech Před rokem +1

      Exactly my thought especially now that we are in the era of more robust styling tools like styled-components

  • @charlie-george
    @charlie-george Před rokem +2

    Where can we find out the information about support for css nesting in browsers and follow the progress of how far along it is to becoming available?

  • @petrvalenta8835
    @petrvalenta8835 Před rokem

    It looks like a quit big "game changer" one day! 😱 Thank you for this!

  • @alihaleem8959
    @alihaleem8959 Před rokem

    Thank you so much ❤❤❤

  • @__s5558
    @__s5558 Před rokem

    Thank you so much sir,,,, really too helpful video and codes ❣️,...thank you again....❣️!

  • @notjackk
    @notjackk Před rokem +12

    Soo it's not actually plain CSS?

    • @WebDevSimplified
      @WebDevSimplified  Před rokem +5

      Yes and no. It is using a polyfill essentially to emulate the behavior of how this would work in normal CSS based on the spec unlike something like SCSS which is its own nesting system.

    • @notjackk
      @notjackk Před rokem +1

      @@WebDevSimplified Okay, that makes sense, thanks

  • @invictuz4803
    @invictuz4803 Před rokem +1

    I skipped a little at the beginning but I feel like it should be clear in the description somewhere if this possible right now and supported by modern browsers, or if it's not even implemented yet. The title makes it sound like it's an old feature.

  • @MichaelWilliams-lr4mb
    @MichaelWilliams-lr4mb Před rokem +6

    That's pretty awesome. I kind of feel like it would have been great to have this in the beginning. Though I can see some growing pains in going from the current version of CSS to the nested CSS.

    • @sebastiangudino9377
      @sebastiangudino9377 Před rokem +4

      You don't have to tho. This is purely optional. And honestly this might not even be used that much in production in the real world simply from the fact that we are now very accustomed to component framework. So we don't really thing about styling the way a .button looks when inside a .card container. We instead just make a card component and that card component has its own scoped styles inside of it. They really took far to long with this, to the point where the problem they were solving is barely even a problem
      Still extremely happy for this tho

    • @brandonetter
      @brandonetter Před rokem +1

      * new feature * -> " I kind of feel like it would have been great to have this in the beginning." -> no shit

    • @sebastiangudino9377
      @sebastiangudino9377 Před rokem

      @@brandonetter Your comment seems to imply the OP's comment is obvious, but it's clear that "It would have been great at the beginning" implies that is not really that great now days. Which makes sense since we simply found other ways around the problem that this feature is trying to solve (Like SASS, the BAM naming convention, components, scoped styles, etc...)

    • @genka14
      @genka14 Před rokem

      @@sebastiangudino9377 with layers and layers of post processing that is prone to errors and pure configuration hell. Once standardized you can get rid of tons of complexity.

    • @sebastiangudino9377
      @sebastiangudino9377 Před rokem

      @@genka14 If you use vite you can create your project in any Frontend Framework (even Vanilla) and you can include Sass by default (As well as TS) with zero hassle.
      Pretty sure Angular always included Sass by default. NextJS supports Scoped styles by Default, as well as SASS and PostCSS, same with Nuxt.
      You don't need "Layers and layers" of preprocessing to achieve this, just one single layer (PostCSS or Sass) and they both play wonderfully with your desired stack

  • @EternalDarknessAboveTheBlueSky

    That final caveat about placing code after the nested parts is a real deal breaker. That's going to cause more issues than it's worth. They should seriously reconsider changing that behavior.

    • @NathG.1.4.
      @NathG.1.4. Před rokem +1

      Sorry newbie around css but why is that a deal breaker? Makes logical sense to me that it shouldnt apply after the nesting as it's unclear what is being targeted.

  • @iorisi
    @iorisi Před rokem

    Kyle be teaching us life lessons here

  • @abderrahimtamda3990
    @abderrahimtamda3990 Před rokem

    Thank u 💓

  • @MrW0rDs
    @MrW0rDs Před rokem +1

    I think it's going to be at least 2 years until we can use this in production. I wonder if this update will touch all versions of OS or only the latest one (eg. iOS13, iOS14, IOS15, IOS16...)

  • @eladshamai
    @eladshamai Před rokem

    Yes finally :D
    Next feature: @apply

  • @Abdullah-el3yk
    @Abdullah-el3yk Před rokem

    Kyle Please also make videos on backend concepts

  • @ColinRichardson
    @ColinRichardson Před rokem

    Does that mean you can't specify two sets of nesting? This seems like a major drawback. I guess we will be sticking with less?
    And there was no mention of being able to do things like &.className (without a space) does that work ?

  • @johnbobbypringle
    @johnbobbypringle Před rokem

    it's so easy to use scss that this doesn't matter especially as my visitors would need such a plugin. Will they be bringing in support for mixins too or is it just nesting? Without the support for mixins, SCSS is still better to use.

  • @chervilious
    @chervilious Před rokem

    Should they create css4 declaration like doctype html. So they can create from scratch

  • @wisdomelue
    @wisdomelue Před rokem

    great!! …still using scss tho thanks

  • @timoernst
    @timoernst Před rokem +11

    This is great news as sass/less compilers are way too slow. Can’t wait for nesting to be supported in all browsers. Still, I find the ampersand to be redundant and decreasing readability of the code 😢

  • @Fighter178
    @Fighter178 Před rokem +1

    Ok, but when will browsers start supporting it so I can use it 5 years from then when everyone has finally switched to a supporting browser?

  • @butbutmybutt
    @butbutmybutt Před rokem

    wow, now 5 years from now on we can use it :)

  • @bernardus3289
    @bernardus3289 Před rokem

    Someday, someday this will be implemented

  • @zakuguriin4521
    @zakuguriin4521 Před rokem

    I'm glad to see CSS finally using this feature from SCSS, but I still think SASS/SCSS is superior to CSS because of the Mixins and Functions.

  • @ChrisWachtman
    @ChrisWachtman Před rokem +1

    Lots of little complexities. Its odd to me that they chose to use the '&' character which is used in sass for a related purpose but very different meaning. Now I'm wondering how could I write scss that compiles to nested css. I imagine that scss would need to be updated with support for this before it can be used. (Although I can't think of a reason to write scss that compiles to nested css...)

    • @SilviuBurcea1
      @SilviuBurcea1 Před rokem

      I think that, over time, CSS standards will adopt more and more sass features and you will eventually give up on it. Or, sass will be like TypeScript or Babel, new features added there, eventually adopted into standard CSS spec.

  • @theodorealenas3171
    @theodorealenas3171 Před rokem +1

    Ouch. I'm not sure. I'd like the opposite: less readable / writeable CSS that depends even more on a transpiler / compiler. And I don't get why it hasn't always been that way instead.

  • @chrisfaux3769
    @chrisfaux3769 Před rokem +4

    I think at first it can seem convoluted as many have already said. But all these limitations could actually be beneficial in the long run, meaning that everybody will be forced to use the same style by avoiding adding nested code when selecting multiple elements (with commas) and adding nested code only at the end of each component. Also strictly using the & as the first selector.

  • @Clint0nKeller
    @Clint0nKeller Před rokem

    Cool!

  • @naoakiusuku9397
    @naoakiusuku9397 Před rokem

    Will it work in the Firefox browser in the future?

  • @TarekFaham
    @TarekFaham Před rokem

    When this will be formally supported?

  • @eliyahutarab4862
    @eliyahutarab4862 Před rokem +3

    maybe the upside of this thing is doing the nesting of media queryies inside of a block like in Sass and thats nice but not as nice you write to many & simbals inside of the code i wont lie its a nice update but Sass in my opinion is just at the moment better!

  • @vladwolf444
    @vladwolf444 Před rokem

    How is this different from other preprocessors? It's not built-in functionality.

  • @NavySturmGewehr
    @NavySturmGewehr Před rokem

    When will browsers natively support nesting?

  • @prudhvichinnam1488
    @prudhvichinnam1488 Před rokem

    How to use this feature in vscode

  • @Technoph1le
    @Technoph1le Před rokem

    Perhaps, they've switched to :where() selector (to remove the specificity) instead of :is() one for the specificity concern...?

    • @WebDevSimplified
      @WebDevSimplified  Před rokem

      The specificication still says :is so that is what I was going off of.

  • @stimolus
    @stimolus Před rokem

    wonder how the nesting looks when debugging styles in browser dev tool? if it shows up as "& p", that's pain in the ass, if dev tools converts "& p" to "article p", all good

  • @geraldopcf
    @geraldopcf Před 3 měsíci +1

    now working
    p{
    color: blue;
    section &{
    color: purple;
    }
    }

  • @bopuc
    @bopuc Před rokem

    hahaha when you changed the text color to blue for a second (before going to white) I was like NOOOOOO! 😅

  • @rishiraj2548
    @rishiraj2548 Před rokem

    👍👍

  • @ulfgj
    @ulfgj Před 5 měsíci

    hey! calling from january 2024 here . is it supported now?

  • @jazzymichael
    @jazzymichael Před rokem

    Why is using a pre-processor considered native CSS? I think native or "plain" CSS should be styles that don't need any processing.

  • @7heMech
    @7heMech Před rokem

    let's goo

  • @FilipCodes
    @FilipCodes Před rokem +1

    How is this better than scss?

  • @aesthet1k_
    @aesthet1k_ Před rokem +2

    Not seeing a compelling reason to ditch SCSS. This syntax is nowhere near the tidiness afforded by SCSS nesting, imo.

  • @dk-fk4xm
    @dk-fk4xm Před rokem

    I'm glad I'm too lazy and stubborn to learn all those fancy css cousins before.

  • @Marujhin
    @Marujhin Před rokem

    Omg!!!

  • @coolemur976
    @coolemur976 Před rokem +5

    Click bait. Title should be "How To Use Nesting In PostCSS" !
    Plain css is plain css. And new feature is available only when all latest browsers support it.

    • @degenyakuza
      @degenyakuza Před rokem

      it is still css🗿

    • @coolemur976
      @coolemur976 Před rokem +1

      @@degenyakuza It's "enhanced" css. So no - that is not "plain css". 😬

    • @badcatdesign
      @badcatdesign Před rokem

      But isn’t the plan that this “will be” the plain css of the future?

    • @coolemur976
      @coolemur976 Před rokem

      @@badcatdesign There is a difference between “how to use” and “how will we be able to use it in the future”. Plain css means - you take document, you put there html + css. And it works without using any enhancement libraries or polyfills. Please, use common sense.

  • @uahnbu
    @uahnbu Před rokem

    I would rather use preprocessing css than plain css with lower compatibility and performance.

  • @l6e6i6n
    @l6e6i6n Před rokem

    this feature is long overdue

  • @___Kevin
    @___Kevin Před rokem

    Promising but I'll stick to scss for the moment

  • @ankitshukla8640
    @ankitshukla8640 Před rokem

    Do you do gaming?

  • @JasimGamer
    @JasimGamer Před rokem

    in sass & means "if class has this"

  • @fun2rideadventure
    @fun2rideadventure Před rokem

    Off topic question...why are you conding on windows and not Mac or Linux?

  • @DannyMancheno
    @DannyMancheno Před rokem +1

    Can we all just agree to use scss

  • @timoernst
    @timoernst Před rokem

    The @nest tag feels very unnecessarily complicated 😵‍💫

  • @informationgiant7697
    @informationgiant7697 Před rokem

    First comment , give me heart

  • @bennybar
    @bennybar Před rokem +1

    "This is has the class red" 💀

  • @heribertojuarez6046
    @heribertojuarez6046 Před rokem +1

    why didn't they think about that when they created it? 😭😭😭

  • @NotKilgamesh
    @NotKilgamesh Před rokem +3

    lol a 11 minute video explaining why SCSS is always better than CSS 😂😂😂

  • @Undrios
    @Undrios Před rokem

    it's been 7 months and it's not supported yet 🙃

  • @tematektematek5085
    @tematektematek5085 Před rokem

    Hi kyle. your speeking is good understandable but very fast for me. unfortunalety, english is not main language for a lot of people, like me. please slowly speek. thanks a lot.

    • @MrW0rDs
      @MrW0rDs Před rokem

      You can change youtube player speed

  • @xxxpirated7756
    @xxxpirated7756 Před rokem

    Seconed

  • @JackOfAllRAIDs
    @JackOfAllRAIDs Před rokem +1

    Sooo... since this isn't supported in any of today's browsers, how is this lesson not useless? Not hatin', genuinely curious.

    • @whatsapp176
      @whatsapp176 Před rokem

      Helpline 📲📩⬆️
      Questions can come in⬆️

  • @hestnet
    @hestnet Před rokem

    Id say its a shame that native nesting is more complicated than in sass/less :(

  • @Nodsaibot
    @Nodsaibot Před rokem

    yes but that is NOT they way we want it, we want for rules to INHERIT the properties of other rules, not to mirror the HTML structure then apply styles to it

  • @nitsanbh
    @nitsanbh Před rokem

    Please avoid "background: red" on half the screen, it hurts to watch it for so long

  • @jgttech
    @jgttech Před rokem +1

    It took CSS 20+ YEARS to do what EVERY other language is capable of by default. That's how bad CSS is. CSS is the ONLY language where people get excited about being able to nest things logically. SASS and LESS are a result of how BAD the CSS language truly is.

  • @bertilow
    @bertilow Před rokem

    Interesting... But Sass seems better, less weird gotchas.

  • @di333
    @di333 Před rokem

    fr fr????

  • @kizhissery
    @kizhissery Před rokem

    SCSS >> CSS

  • @jseh_
    @jseh_ Před rokem

    sass is dead :v?

  • @avneet12284
    @avneet12284 Před rokem

    This is good but it has so many weird gotchas.

  • @Dev-Siri
    @Dev-Siri Před rokem

    Alright, time to ditch Sass

  • @rfryanfavour4369
    @rfryanfavour4369 Před rokem

    Sass ( SCSS ) Is gone lol 😆 💀

  • @KuopassaTv
    @KuopassaTv Před rokem

    CSS creators sure like to bloat

  • @lukasrudolf9868
    @lukasrudolf9868 Před rokem

    Meh, I stick with SCSS.

  • @ShakilShahadat
    @ShakilShahadat Před rokem

    CSS nesting is a available in SCSS for a long time. Your title says, 'in plain CSS' and then you talk about how it can be done using postCSS. What a cheater.

  • @rubenverster250
    @rubenverster250 Před rokem

    SCSS is king ok
    SCSS compiler slow? Get a faster machine
    SCSS is too difficult? I don't think web development is for you...

  • @digitalkoh
    @digitalkoh Před 11 měsíci

    not worth it

  • @DaviddeKloet
    @DaviddeKloet Před rokem

    "specificity" is the absolute worst thing since the Triassic extinction event.

  • @0xtz_
    @0xtz_ Před rokem

    i use scss just bc of the Nesting now no more scss