Interpolation is the umbrella feature behind both selector variables and property variables covered in the previous two lessons. This lesson pulls it all together and covers the remaining places interpolation works: values, URLs, and import paths.
What Is Interpolation in LESS?
Interpolation, written @{name}, injects a variable's resolved value directly into a larger piece of text, whether that's a selector, a property name, a string, a URL, or an import path. It's the mechanism that makes LESS's dynamic selectors and property names possible.
The core rule to remember: use @name when the variable is the entire value, and @{name} whenever the variable is embedded inside something larger.
Interpolation works inside selectors, property names, quoted strings, and URLs.
It also works inside @import paths, though this is rarely needed in practice.
Interpolation always requires curly braces; a bare @name inside a larger string will not be substituted.
The interpolated value is inserted as plain text, with no additional quoting or escaping applied automatically.
LESS Interpolation Cheatsheet
Every context where @{name} interpolation is valid.
Context
Example
Notes
Selector
.@{name} { }
Builds a dynamic class or ID name
Property name
@{prop}: value;
Builds a dynamic property name
String value
content: "@{text}";
Embeds a variable inside quoted text
URL
url("@{path}/icon.svg")
Builds a dynamic asset path
Import path
@import "@{dir}/file";
Rarely used, but valid
Media feature
@media (min-width: @{bp})
Requires the value to resolve to valid syntax
Interpolation in URLs
A common real-world use case is building a themed or environment-specific asset path from a shared base variable, keeping every url() reference consistent if the base path ever changes.
Interpolation inside a quoted string is useful for building dynamic content values, data-* attribute selectors, or debug output that combines a variable with surrounding literal text.
It's worth explicitly recapping the three interpolation contexts covered across this and the previous two lessons, since each solves a distinct real-world problem.
Selector interpolation: dynamic class, ID, and attribute selector names.
String and URL interpolation: dynamic text content and asset paths.
Common Mistakes
Forgetting curly braces and writing @name instead of @{name} when embedding a variable inside a larger string.
Assuming interpolation automatically adds quotes or escaping around the substituted value; it inserts plain text exactly as resolved.
Using interpolation in a media feature with a value that doesn't resolve to valid CSS syntax, like a color instead of a length.
Overusing interpolation for values that would be clearer as a normal, single @name property value.
Key Takeaways
Interpolation (@{name}) injects a variable's value into a larger piece of text: a selector, property name, string, or URL.
Use plain @name when the variable is the entire value; use @{name} when it's embedded inside something larger.
Interpolation is most valuable for dynamic selectors (utility class generation) and dynamic asset URLs.
Interpolated values are inserted as plain text with no automatic quoting or escaping.
Pro Tip
Whenever you're not sure whether to use @name or @{name}, ask whether the variable is the *entire* value or just *part* of a larger string. Entire value: plain @name. Part of something larger: @{name}.
You now have a complete picture of LESS interpolation. Next, revisit guards in more depth, focusing on real-world conditional patterns.