SCSS Nesting
Avoid unnecessary nesting. Just because you can nest, doesn’t mean you should. Consider nesting only if you must scope styles to a parent and if there are multiple elements to be nested.
// Bad nesting
.parent {
h1 { }
span { }
a { }
}
// Good nesting (in this case no nesting)
.parent-heading { }
.parent-subheading { }
.parent-permalink { }
// Bad nesting
.parent {
.parent-child { }
.parent-child2 { }
.parent-modifier { }
.parent-modifier2 { }
}
// Good nesting
.parent-child { }
.parent-child2 { }
.parent-modifier { }
.parent-modifier2 { }
Additional reading:
More Stylesheets tutorials
-
SCSS Math Operators
Best practices for writing easy to maintain stylesheets.
-
CSS Syntax
Best practices for writing easy to maintain stylesheets.
-
CSS Shorthand Notation
Best practices for writing easy to maintain stylesheets.
-
CSS Selectors
Best practices for writing easy to maintain stylesheets.
-
CSS Media Queries
Best practices for media queries inside your stylesheets.
-
CSS Declaration Order
Best practices for order of declarations inside stylesheet elements.
-
CSS Class Names
Best practices for writing easy to maintain stylesheets.
-
Code Comments
Best practices for writing easy to maintain code.
-
SCSS Extend and Mixin
Best practices for writing easy to maintain stylesheets.