Sass Parent Selector

Beginner
9 min read
Updated: Nov 2026
5 examples
Dart Sass

Definition and Usage

The parent selector & refers to the outer selector inside a nested rule. Sass replaces & with that outer selector instead of the default descendant join (a space).

Official sample idea.

&:hover becomes .alert:hover; [dir=rtl] & becomes [dir=rtl] .alert.

BEM suffixes.

If the parent ends with a class/ID/element name, append text: &__copy, &--open.

Not span&.

& must start a compound selector where a type selector would be allowed. span& is invalid.

Syntax

SCSS
.alert {
  &:hover { ... }        // .alert:hover
  &.is-active { ... }    // .alert.is-active
  [dir=rtl] & { ... }    // [dir=rtl] .alert
  :not(&) { ... }        // :not(.alert)
  &__copy { ... }        // .alert__copy
}

// In SassScript: & is the current parent (or null outside rules)
@if & { ... }

Pattern: nest under a parent → place & where the outer selector should appear → compile attached selectors.

Common Patterns

Where & usually appears:

PatternResult idea
&:hover / &:focusPseudo-class on the parent
&.is-activeExtra class on the same element
.context &Parent when inside another selector
&__el / &--modBEM-style name suffixes
& in SassScriptCurrent parent selector, or null outside rules

SCSS Examples

Open View Compiled CSS for verified Dart Sass output (matches official Sass docs samples where shown).

Example 1 — Official Parent Samples

Pseudo-class, outer context, and :not(&).

SCSS
.alert {
  &:hover {
    font-weight: bold;
  }

  [dir=rtl] & {
    margin-left: 0;
    margin-right: 10px;
  }

  :not(&) {
    opacity: 0.8;
  }
}

How It Works

  1. &:hover attaches a pseudo-class.
  2. [dir=rtl] & places the parent after a context.
  3. :not(&) passes the parent into a pseudo-class.
  4. Matches the official Sass docs sample.

Example 2 — BEM Suffixes

Append __ / -- text when the parent ends with a name.

SCSS
.accordion {
  max-width: 600px;

  &__copy {
    display: none;

    &--open {
      display: block;
    }
  }
}

How It Works

  1. &__copy appends to .accordion.
  2. Nested &--open appends to .accordion__copy.
  3. No space between block and element.
  4. Matches the official BEM-style sample idea.

Example 3 — Same-Element Modifier

Attach another class to the parent with &.is-active.

SCSS
.btn {
  color: #111;

  &.is-active {
    color: #000;
  }
}

How It Works

  1. Without &, nesting would make a descendant.
  2. &.is-active keeps both classes on one element.
  3. Result is .btn.is-active.
  4. Common for state classes.

Example 4 — Detect Nesting in a Mixin

Outside a rule, & is null (falsey)—branch accordingly.

SCSS
@mixin app-background($color) {
  @if & {
    &.app-background {
      background-color: $color;
    }
  } @else {
    .app-background {
      background-color: $color;
    }
  }
}

@include app-background(#036);

.sidebar {
  @include app-background(#c6538c);
}

How It Works

  1. Root include sees & == null.
  2. Nested include sees the parent selector.
  3. &.app-background attaches when nested.
  4. Matches the official mixin-detection idea.

Example 5 — selector.unify + @at-root

Advanced: combine & with an element selector without double-nesting.

SCSS
@use "sass:selector";

@mixin unify-parent($child) {
  @at-root #{selector.unify(&, $child)} {
    @content;
  }
}

.wrapper .field {
  @include unify-parent("input") {
    border: 1px solid;
  }
}

How It Works

  1. unify merges & with input.
  2. @at-root prevents wrapping the outer selector again.
  3. Result is .wrapper input.field.
  4. Details on selector.unify().

Edge Cases & Pitfalls

Most & bugs are forgetting it for states or misplacing it in a compound selector.

space

Default nesting adds a space

Without &, nested :hover is not the same as &:hover. See nesting.

span&

Cannot suffix a type onto &

span& is invalid. Keep & at the start of the compound selector.

null

& is null outside style rules

Useful in mixins; do not assume a parent always exists.

@at-root

Interpolating & still nests

Use @at-root when combining with selector functions so Sass does not wrap again.

Sass Support

Parent selector is core Sass nesting on Dart Sass.

FeatureStatus
& in nested selectorsSupported
BEM-style suffixesSupported when parent ends with a name
& outside nestingDart Sass 1.100+ emits plain CSS &
SassScript &Parent selector value, or null outside rules

Compile with the Dart Sass CLI.

Key Takeaways

  • & stands in for the outer selector.
  • &:hover / &.mod / &__el — no extra space.
  • Context & like [dir=rtl] & places the parent later.
  • null outside rules — great for mixin branches.

One line: use & whenever nesting should attach to the parent instead of creating a descendant.

Compile Notes

Practical checklist:

checklist.txt
1. Nest under a parent rule
2. Write &:hover / &.is-active / &__el as needed
3. Put context selectors before & when required
4. Remember & is null outside style rules
5. Use @at-root with selector functions that interpolate &

Frequently Asked Questions

The ampersand & is a special selector that refers to the outer (parent) selector inside a nested rule. Sass replaces & with that outer selector instead of using normal nesting.
Nest &:hover { ... } inside the parent rule. .button { &:hover { opacity: 0.9; } } compiles to .button:hover { opacity: 0.9; }.
If the outer selector ends with a class, ID, or element name, you can append text: &__element and &--modifier become .block__element and .block__element--modifier.
Yes for context. [dir=rtl] & becomes [dir=rtl] .alert. But span& is not allowed—& must start a compound selector where a type selector would be allowed.
As an expression, & returns the current parent selector as a list of lists of unquoted strings. Outside any style rule it returns null, which is useful to detect whether a mixin was included inside a rule.
When you interpolate &, Sass still nests the outer selector automatically. @at-root tells Sass not to wrap again, so advanced selector math stays correct.

Next: Sass Placeholder Selectors

Create silent % selectors to share styles with @extend.

Placeholders →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful