Format Code Now
/
ConvertCSS to LESS Converter Next: CSS to Sass Converter ›

CSS to LESS Converter

CV-41

Valid CSS is already valid LESS, so this tool does the part that helps: it nests rules that share a parent selector, writes selector lists one per line and indents to the width you choose.

Runs in your browser. Nothing is uploaded.

CSS code

LESS code

How to use it

  1. Paste your CSS into the input box, or open a .css file.
  2. Leave Nest rules that share a parent selector on to get nested LESS, or turn it off for a flat copy.
  3. Pick the indent width and press Convert to LESS.
  4. Copy the LESS or download it as a .less file.

What changes in your file

A rule that directly follows another and starts with its selector is moved inside it. ".nav" followed by ".nav a" and ".nav:hover" becomes one .nav block holding a and &:hover. Child combinators come out as "> .x". Comments are kept, and values, strings and url() data are copied as written.

What it does not do

It does not invent variables, mixins or functions: finding repeated colors and turning them into @variables is a judgement call, so it is left to you. Rules separated by other rules are not merged, because moving them would change the cascade order. Selector lists with commas stay as separate rules.

Check the result

The nested LESS compiles back to the same CSS in the same order, which you can confirm with the LESS to CSS compiler on this site. A // comment inside a declaration is dropped. If a file is large, convert a section first to see the pattern before pasting everything.

Error messages and what to do

MessageWhat it meansFix
Missing } to close the block opened on line 3.A rule or at-rule was opened with { and never closed.Add the missing } at the end of the block that starts on the named line.
Unexpected } on line 5: there is no block to close.There is a } with no matching {.Delete the extra } or add the { it belongs to.
Unterminated /* comment starting on line 2.A /* comment has no closing */.Close the comment with */.

Questions people ask

How do I convert CSS to LESS?

Paste your CSS and press Convert to LESS. Because CSS is valid LESS, the output works as it is. With nesting on, related rules are grouped under their parent selector so the file reads like hand-written LESS.

What does the nesting option do?

When a rule directly follows a rule whose selector it starts with, it is moved inside it. ".card .title" after ".card" becomes ".title" inside ".card", and ".card:hover" becomes "&:hover". Only neighbouring rules with single selectors are merged, so the compiled CSS keeps the same order.

Does it create LESS variables from my colors?

No. It only changes structure. Choosing which values become @variables depends on your design, and a wrong guess would add noise. Add the variables you want after converting, then replace the repeated values.

Is the converted LESS the same as the CSS?

Compiled, yes: nested rules produce the same selectors in the same order. It is safe to check by running the output through the LESS to CSS compiler. Rules that were not neighbours are left in place so the cascade does not change.

Can I convert minified CSS to LESS?

Yes, minified CSS is parsed like any other, and the output is formatted with indentation. Minified comments and values are copied as they are. Nesting works the same way as long as the related rules sit next to each other.

About this tool

Valid CSS is already valid LESS, so this tool does the part that helps: it rewrites the file in LESS syntax and, if you leave the nesting option on, nests a rule under the rule before it when its selector starts with that rule's selector, for example .card .title after .card, or .card:hover written as &:hover. Only neighbouring rules are merged and only single selectors without commas, so the compiled CSS keeps the same order. Rules separated by other rules are left flat. It does not invent variables or mixins. Selector lists are split one per line, and a // comment inside a declaration is dropped.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.