What the LESS to CSS converter does
Browsers do not understand LESS, so every LESS stylesheet must be turned into CSS before it ships. This LESS to CSS converter runs the official less.js compiler (version 4) in your browser and prints readable, expanded CSS. Use it to see what a component's styles really produce, to extract the CSS from an old theme, or to hand plain CSS to someone who does not use LESS.
Example
@sizes: { small: 12px; large: 20px; }
.text(@mode) when (@mode = muted) { color: #6b7280; }
.caption {
font-size: @sizes[small];
.text(muted);
&::before { content: "— "; }
}
.heading { font-size: @sizes[large]; width: ~"calc(100% - 20px)"; }
.caption {
font-size: 12px;
color: #6b7280;
}
.caption::before {
content: "— ";
}
.heading {
font-size: 20px;
width: calc(100% - 20px);
}
The detached-ruleset map @sizes was looked up with @sizes[small], the guarded mixin matched because @mode = muted, and the escaped string ~"calc(...)" was output without quotes, a classic LESS trick to stop the compiler from evaluating calc().
What gets evaluated
- Variables, including lazy evaluation: a variable can be used before it is defined, and the last definition in scope wins.
- Mixins with parameters, guards (
when), pattern matching and!important. - Operations:
+,-and*always; division only inside parentheses in LESS 4. - Functions such as
darken(),fade(),percentage()ande(). - Nesting,
&references and media query bubbling.
Things that cannot be converted here
Local @import statements fail because the converter has no access to your files: paste the imported variables or mixins at the top of your code instead. Inline JavaScript evaluation with backticks is disabled, as in current LESS defaults. This page always outputs expanded CSS; for a minified result use the LESS Compiler with Minify output, or pass the CSS through the CSS Minifier.
Checking the result
Source order is preserved
less.js writes rules in the order they appear in your source, with nested rules placed right after their parent. That order matters in CSS: when two selectors have the same specificity, the later one wins. If you reorganize the LESS before converting, compare the CSS order too, not just the declarations.
Compare the generated selectors with your intentions. Deep LESS nesting turns into long selectors with high specificity, and mixins called in many places repeat their declarations in every rule. If the CSS is much larger than expected, look for mixins that could be replaced with :extend or a shared class. To get a nested, Sass-flavored version of the same styles, try LESS to SCSS. Conversion happens in your browser.