When to Nest CSS – Cloud Four

March 25, 2024

With the recent news that CSS nesting is now available in the major evergreen browsers, our team was discussing how it differs from nesting in Sass, and the question came up — When should you use nesting?

There’s a simple answer and a slightly more complicated answer. The simple answer is “avoid nesting.” The more practical, but also more complex answer is “nest pseudo-selectors, parent modifiers, media queries, and selectors that don’t work without nesting.”

Let’s discuss it a little bit, but first, I’ll give my standard disclaimer: This is what works for our team, it’s not a carved-in-stone standard, and you’re welcome to ignore this advice if it doesn’t work for your situation.

Source: When to Nest CSS – Cloud Four

Nesting is one of a number of syntactical innovations to CSS that pre processors like Sass brought that developers have long wanted in the core language itself.

Now it’s here.