Share X in

1. Nest child selectors

Keep component styles together without repeating the parent class.

Nested card

Title

Body text styled from a nested rule.

The h3 and p rules live inside the .nest-card block.

.card {
  padding: 1rem;
  h3 { margin: 0; }
  p { color: #64748b; }
}

2. The & nesting selector

Use & for hover, focus, and compound selectors.

Hover button

The &:hover rule is nested inside .nest-btn.

.btn {
  background: #2563eb;
  &:hover { background: #1d4ed8; }
  &.is-active { background: #7c3aed; }
}

3. Nest media queries

Co-locate responsive rules with the component.

Responsive box
Padding grows at 40rem

The nested @media changes padding on wider screens.

.panel {
  padding: 1rem;
  @media (min-width: 40rem) {
    padding: 2rem;
  }
}

Frequently asked questions

Do I still need Sass for nesting?
For nesting alone, no. Native CSS nesting works in all current browsers. Sass still helps with mixins, loops, and functions.
Is the & selector always required?
Not for plain descendant selectors, but it is required for compound selectors like &.active and clearer for states like &:hover.
Can I nest too deeply?
You can, but deep nesting raises specificity and hurts readability. Keep nesting to two or three levels.