Sass·Sass from variables to a design system

Nesting

Nest selectors for readability without creating fragile specificity.

Intermediate 12 min read Lesson 3 of 300 Challenge included
What you will be able to do
  • Keep nesting to two or three levels.
  • Use & for hover, focus and modifiers.
  • Do not nest just to avoid class names.
  • Prefer flat utility classes where appropriate.

In plain English

Nesting mirrors the DOM but should stay shallow. The parent selector & refers to the outer selector, which is perfect for states and modifiers. Deep nesting creates long selectors and coupling.

nesting.scssSCSS
.card {
  padding: 16px;

  &:hover { border-color: #2f74c0; }
  &.is-featured { box-shadow: 0 8px 24px rgb(0 0 0 / 0.12); }

  .title { font-weight: 700; }
}
Your turn

Add a hover state

Easy

Use & inside .card to style :hover.

SCSS · starter
.card { }
Check your understanding before moving on.
Knowledge checkQuestion 1

What does & refer to?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Partials and imports
Lesson 3 of 300 · 0% of course