LESS Beautifier
WM-91Paste LESS and get tidy, consistently indented code back. Variables, mixins and nested rules are kept as you wrote them.
Runs in your browser. Nothing is uploaded.
LESS
Formatted LESS
How to use it
- Paste your LESS, or open a .less file or drop it on the input box.
- Pick 2 spaces, 4 spaces or a tab, and tick single quotes if you want them.
- Press Beautify.
- Copy the result or download it as a .less file.
What stays and what moves
The formatter uses Prettier with its LESS-aware CSS parser. Variables such as @primary, mixin definitions and calls, parametric mixins, guards, operations and nested selectors with & all survive. Each declaration goes on its own line, braces are placed consistently, a space follows each colon in a declaration, and nesting is indented one level at a time. Comments, both // and /* */, are kept.
LESS versus CSS output
The result is still LESS. Nothing is compiled, so variables are not replaced and mixins are not expanded. To get plain CSS you need the LESS compiler, or the CSS formatter on this site after compiling. A mixin that does not exist or a variable that is never defined is not reported, because that needs the compiler.
Errors and oddities
If the LESS cannot be parsed, such as a rule with a missing closing brace, you get the message with a line and column. A few unusual mixin parameter forms are printed as typed, so the spacing inside a mixin signature may not change. Output follows the Prettier version in this page.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Could not format the LESS: Unclosed block at line 1, column 1. | A rule was opened with { but never closed with }. | Add the missing closing brace at the end of the block that starts at the line shown. |
Questions people ask
How do I beautify LESS online?
Paste your LESS into the box and press Beautify. Rules are indented, each declaration sits on its own line, and nested blocks are laid out under their parent. Copy or download the result.
Does it compile LESS to CSS?
No. It only formats. Variables and mixins stay in the output as written. Use the LESS compiler to produce CSS. Variables and mixins stay in the output as written, so the result is still LESS and not CSS. Use the LESS compiler when you need plain CSS for a browser.
Will it keep my comments?
Yes. Both line comments with // and block comments are kept in place next to the code they sit beside. Both line comments written with two slashes and block comments are kept in place next to the code they sit beside, and their text is not reflowed.
Does it support mixins and guards?
Yes. Mixin definitions, calls with arguments, and guard conditions are parsed. A few rare parameter styles are left as typed. Mixin definitions, calls with arguments and guard conditions are parsed. A few rare parameter styles are printed as typed, so their spacing may not change.
Why did my output keep @primary*2 tight?
Operations are printed as typed in some cases, so spacing around the operator may not change. The formatter avoids rewriting expressions it cannot be sure about.
About this tool
Formats LESS with Prettier and its postcss-less parser. Variables, mixins, guards, nesting, operations and comments are kept as written; only spacing, line breaks and indentation change. The code is not compiled, so a mixin that does not exist or a variable that is never defined is not reported. Only syntax errors give a message, with line and column. The output is still LESS, not CSS; to get plain CSS you need the LESS compiler. Output follows the Prettier version in this page.