Placeholder Selectors and @extend
A placeholder selector begins with % and is not emitted as a standalone selector unless it is extended by another selector. It is useful for sharing a set of declarations among related selectors.
The @extend directive allows a selector to inherit the selector rules associated with another selector. Sass may combine selectors in generated CSS, which can create larger selector groups than expected.
Mixins and placeholders serve different purposes. Mixins copy declarations into each inclusion point, whereas placeholders and @extend participate in selector unification. Neither is universally superior.
Prefer mixins when the caller needs different parameter values or when explicit component output is desirable. Consider placeholders for tightly related selectors that genuinely share a structural rule set. Avoid extending broad selectors across unrelated components.
Declarations expanded at include sitesSupportedSelectors unifiedNot a mixin-style parameter API%message-base {
padding: 1rem;
border-radius: 0.5rem;
}
.success-message {
@extend %message-base;
color: #155724;
background: #d4edda;
}
.error-message {
@extend %message-base;
color: #721c24;
background: #f8d7da;
}@extend, especially when extending selectors with complex relationships. Selector unification can produce output that is less obvious from the SCSS source.What happens to a placeholder selector such as `%message-base` when it is not extended?