liveBook · Manning

Sass @extend at-rule

As explained in Tiny CSS Projects

The Sass @extend at-rule adds a selector to the selector list of another rule so it shares that rule's declarations.

Sass @extend lets one selector share another rule’s declarations. It adds the extending selector to the base rule’s selector list, avoiding duplicated static properties. section 12.2.1

Reuse a base image style

Define shared dimensions and object handling once, then extend that rule for each image: `.image-base { width: 300px; height: 300px; object-fit: cover; margin: 0 2rem; }`, followed by `img:first-of-type { @extend .image-base; }`. Sass outputs one grouped rule containing `.image-base` and the three image selectors. section 12.2.1

Choose @extend when shared values are static:

  • Extending adds selectors to an existing rule rather than copying or generating declarations. section 12.3.3
  • Mixins generate declarations and accept parameters, making them better for dynamic property values. section 12.3.3
  • A loop can extend a shared `.callout` rule while generating separate success, warning, and error styles. section 12.5

How Tiny CSS Projects covers it

How deep it goes
Explains selector-list output through image and callout examples, then contrasts generation with mixins.
Examples
Demonstrates shared image dimensions and callout styling for success, warning, and error states.
What it assumes
Assumes CSS selectors and rules, while introducing Sass’s SCSS syntax and reusable base-rule pattern.
What you can do after
Apply via Sass to share static styles without duplicating declarations, and distinguish extension from parameterized mixins.
How it connects
Connects @extend to Sass rules, mixins, @each loops, interpolation, and grouped CSS selectors.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny CSS Projects. The section links point to the parts of the book it draws on.