2023-12-27
2027
#css
Sarah Chima Atuonwu
69819
Dec 27, 2023 â‹… 7 min read

Native CSS nesting: What you need to know

Sarah Chima Atuonwu I am a Fullstack software developer that is passionate about building products that make lives better. I also love sharing what I know with others in simple and easy-to-understand articles.

Recent posts:

Simplifying CSS Animations With The `Display` And `Size` Properties

Simplifying CSS animations with the display and size properties

New CSS features simplify animating elements by allowing transitions for display and size properties, reducing the need for complex JavaScript workarounds.

Saleh Mubashar
Oct 24, 2024 â‹… 7 min read
The Best React Select Component Libraries

The best React select component libraries

Explore select libraries in React, including React Select and alternatives like Downshift, Choice.js, and more.

Jude Miracle
Oct 23, 2024 â‹… 7 min read

A guide to the best email editing tools

Learn about open-source and free email editors that streamline template creation, and then check out how to test them.

Isaac Okoro
Oct 22, 2024 â‹… 4 min read
Deep Dive React Fiber

A deep dive into React Fiber

Learn about React Fiber, an internal engine change geared to make React faster and smarter by solving the DOM tree issue.

Karthik Kalyanaraman
Oct 22, 2024 â‹… 20 min read
View all posts

6 Replies to "Native CSS nesting: What you need to know"

  1. Maybe not best to use it unless totally necessary, as SCSS still has advantages of not requiring to use that many ampersands in the code. And it can easily be forgotten or that it can catch errors before the compiling has completed. And also that we have modules that we can work from which would make it ideal. But either way would be good to have that as native.

    Kind regards,
    Michael

  2. BBEdit can reformat these before and after examples to be much easier to understand. For instance, here’s the over-nested example:

    main
    {
    & section { background-color: red;
    & ul { background-color: green;
    & .list { font-size: 16px;
    & .link { color: pink;
    &: hover { color: blue;
    }

    main section { background-color: red; }
    main section ul { background-color: green; }
    main section ul .list { font-size: 16px; }
    main section ul .list .link { color: pink; }
    main section ul .list .link:hover { color: blue; }

  3. After writing Less, Sass, SCSS, Stylus, back to SCSS… and now spending a year with no pre-processor: it’s hard to imagine using this syntax. As huge fans of nesting… we can’t believe we’re come to a point where we might just prefer not to. If we could skip the & on every line, and we also had HTTP2 or something concatenate the files natively, maybe it would be a winner. We’ll cross our fingers for something better to happen… or wait to evolve our stance.

  4. Hi Sarah, thanks a lot. About “Styles after nested selectors are ignored”, it works on my side so does it depends of the browser?

Leave a Reply