Composing CSS Properties with Less Merge: A Practical Guide
Less's merge feature lets you accumulate CSS property values across mixins instead of overriding them. Learn how space-merge and comma-merge work, see a composable card example, and understand the debugging limitations.
11 Jul 2026, 19:32 UTC

The problem: overriding instead of accumulating
When you build UI components with mixins, you often need to layer multiple values for the same property — think box-shadow for depth, transform for chained movements, or transition for staggered animations. In vanilla CSS (and in most preprocessors), the last declaration wins. If a base mixin sets box-shadow: 0 2px 4px rgba(0,0,0,.1) and a variant mixin adds box-shadow: 0 8px 16px rgba(0,0,0,.2), the first shadow disappears. You end up duplicating the entire stack in every variant or resorting to awkward variable interpolation.
Less solves this with the merge feature: a declarative way to concatenate values for the same property within a ruleset. Instead of overriding, each mixin appends its contribution. The result is a single property with all values combined, exactly as the browser expects.
How merge works in Less
Merge uses two operators:
+(space-merge) — joins values with a space. Use for properties likebox-shadow,transform,filter, and custom properties that accept space-separated lists.+_(comma-merge) — joins values with a comma. Required fortransition,background,animation, and any property whose syntax is comma-separated.
Both operators only work when the property already exists in the current ruleset (or a parent ruleset that is being merged into). A plain declaration after a merged one will override the entire stack — the merge chain is discarded.
Worked example: a composable card component
Below is a minimal Less file you can compile with lessc. It demonstrates space-merge for shadows and transforms, and comma-merge for transitions.
// base.less
.card-base() {
box-shadow+: 0 1px 2px rgba(0,0,0,.08);
transform+: translateZ(0); /* forces GPU layer */
transition+_ transform 0.15s ease-out;
}
.card-elevated() {
box-shadow+: 0 4px 12px rgba(0,0,0,.12);
transform+: scale(1.02);
transition+_ box-shadow 0.2s ease-in;
}
.card-interactive() {
transition+_ opacity 0.1s linear;
}
.card {
.card-base;
.card-elevated;
.card-interactive;
/* plain declaration would wipe the merged stack:
box-shadow: 0 0 10px red; */
}Compile with lessc --verbose base.less (run in your project root; requires less installed via npm). The output CSS for .card becomes:
.card {
box-shadow: 0 1px 2px rgba(0,0,0,.08) 0 4px 12px rgba(0,0,0,.12);
transform: translateZ(0) scale(1.02);
transition: transform 0.15s ease-out, box-shadow 0.2s ease-in, opacity 0.1s linear;
}Each mixin contributes a piece; the final rule is valid CSS with all values combined. No manual list management, no interpolation strings.
Choosing the right merge mode
The operator must match the property's value syntax. A quick reference:
| Property | Merge operator | Reason |
|---|---|---|
box-shadow | + | Space-separated list of shadow layers |
transform | + | Space-separated transform functions |
filter | + | Space-separated filter functions |
transition | +_ | Comma-separated transition definitions |
background | +_ | Comma-separated background layers |
animation | +_ | Comma-separated animation definitions |
Using + on transition produces transition: transform 0.15s ease-out box-shadow 0.2s ease-in — invalid CSS that browsers ignore. The verbose compiler output (--verbose) will show the merged value but won't flag the syntax error; validation happens in the browser.
Limitations and debugging tips
- No deduplication. Including the same mixin twice appends duplicate values. In the example, calling
.card-basetwice would produce two identicaltranslateZ(0)transforms. Audit your mixin inclusion graph or guard with a sentinel variable if needed. - Override wipes the stack. A plain
box-shadow: ...anywhere after the lastbox-shadow+:in the same ruleset discards all merged shadows. Keep plain declarations before any merge declarations, or avoid them entirely in merged rulesets. - DevTools hides the steps. Browser inspectors show only the final computed value. To trace merge operations, compile with
lessc --strict-math=off --verboseand read the compiler log; it prints each merge step with the source line. - Scope is ruleset-local. Merge does not cross
@importboundaries unless the imported file is inlined via@import (less)or@import (inline). Plan your file structure accordingly.
Verify before you adopt
Create a test file with the example above and compile against the Less versions you target (2.7.x, 3.13.x, 4.2.x). The merge semantics have been stable since 1.5.0 (2014), but running lessc --version and diffing the output ensures no tooling regression. Check that:
- Space-merged properties use spaces in the output.
- Comma-merged properties use commas.
- A plain declaration after merges overrides the entire property (comment it out to confirm the stack returns).
If the output matches expectations, you can safely introduce merge into your component library. Start with box-shadow and transition — they're the highest-leverage properties for this pattern — and expand once the team is comfortable with the debug workflow.