The :extend() pseudo-class lets one selector inherit another selector's matching rule, merging them together in the compiled output instead of duplicating declarations the way a mixin call would.
What Does :extend() Do?
When you write .button:extend(.base-button) {}, LESS finds every compiled rule where .base-button appears and adds .button to that same selector list. The declarations themselves are written only once in the output.
This is different from calling a mixin, which copies the mixin's declarations into every selector that calls it, duplicating the actual CSS properties in the output.
Choosing between a mixin call and :extend() is mostly about compiled output size. A mixin copies its full declaration block into every caller; extend merges selectors so the declarations exist exactly once.
The extend version's compiled CSS repeats padding and border-radius zero times instead of twice.
Using the all Keyword
By default, :extend() only matches a selector when it appears standalone. Adding the all keyword also matches the target selector when it's part of a compound or nested selector elsewhere in the file.
Extend is the better choice when a group of selectors share identical static declarations with no parameters. Once you need arguments, defaults, or conditional logic, a parametric mixin is the right tool instead.
Use extend for shared, parameter-free declaration blocks (like a base alert or message style).
Use mixins when you need to pass arguments, like a color or size.
Use mixins when the shared logic includes guards or conditional behavior.
Common Mistakes
Using :extend() when a mixin's parametric behavior (colors, sizes) is actually needed instead.
Forgetting the all keyword when trying to extend a selector that only ever appears as part of a compound selector.
Assuming extend copies declarations like a mixin does; it actually merges selectors, producing zero duplication.
Extending a placeholder-style class that doesn't otherwise exist in the compiled output, silently producing no effect.
Key Takeaways
:extend() merges a selector into every compiled rule matching its target, instead of duplicating declarations.
It can be written directly on a selector or nested with &:extend(...) inside a block.
The all keyword also matches the target selector inside compound and nested selectors.
Choose extend for shared static styles, and a parametric mixin when arguments or guards are needed.
Pro Tip
Reach for :extend() when several selectors need identical, parameter-free base styles (like alerts or badges); it keeps compiled CSS smaller than the equivalent mixin calls.
You now understand how :extend() merges selectors in LESS. Next, dive into LESS Mixins, the most widely used LESS feature.