LESS Formatter Online — Free Tool
LESS Formatter
Paste LESS and Format reflows it with a consistent layout. It runs Prettier's less parser in your browser (formatLess in src/lib/Lang/v2/css/CssService.ts). It changes layout and quote style. It does not compile LESS, so variables, mixins and guards stay as written. Nothing is uploaded.
How this tool formats it
- Parser. Prettier's
lessparser, with the postcss plugin. - Indentation. The Indent control sets 2, 3, 4 or 8 spaces, and the default is 2. The value is stored under
css-indent-spaces, which the other CSS routes share. - Quotes. Single-quoted strings become double-quoted:
'ok'becomes"ok". Escapes such as~"esc"are kept. - Variables, mixin calls and guards are kept as written.
.m();stays a call, andwhen (...)stays a guard. - Variables are not resolved. An undefined
@nopeis not an error. - Syntax errors become output text.
formatLesscatches the parser error and returnsError:followed by the message. The output pane shows it, and the input is left as you typed it.
Worked example
Input:
@brand: #3b82f6;
.m() when (@a > 0) { color: red; }
.button { .m(); color: @brand; content: 'ok'; width: (@w * 2); }Output from this tool, with the Indent control at 2:
@brand: #3b82f6;
.m() when (@a > 0) {
color: red;
}
.button {
.m();
color: @brand;
content: "ok";
width: (@w * 2);
}The guard and the mixin call are kept, @brand is not replaced with its value, and 'ok' is double-quoted.
Gotchas
1. Single quotes become double quotes. Input .a { content: 'ok'; } gives:
.a {
content: "ok";
}2. Undefined variables pass through. Input .a { color: @nope; } gives:
.a {
color: @nope;
}The formatter does not evaluate LESS, so the missing variable is not reported.
3. Mixin calls are not expanded. Input .m() { color: red; } .button { .m(); } gives:
.m() {
color: red;
}
.button {
.m();
}To see the compiled CSS, use the LESS to CSS tool.
4. A syntax error replaces the output with text. Input .a { color: red gives this in the output pane:
Error: CssSyntaxError: Unclosed block (1:1)
> 1 | .a { color: red
| ^The input pane keeps your text. Fix the input and format again.
Use the formatter when you want a LESS file to match a layout convention. Use the LESS to CSS tool when you want compiled output.
FAQ
Does the formatter compile LESS to CSS?
No. Use the LESS to CSS tool for compiled output.
Can I change the indentation?
Yes. The Indent control accepts 2, 3, 4 and 8 spaces. With 3 spaces the worked example's .button block is indented by three spaces per level.
Does it catch an undefined variable?
No. Only parser-level errors, such as an unclosed block, are reported.