FormatterHQ

CSS to LESS Converter

Turn flat CSS into nested LESS. Child selectors move inside their parent rule and pseudo-classes become &:hover, giving you a structured starting point.

Input CSS
Output LESS
Ready.

How to use the CSS to LESS Converter

  1. Paste your CSS into the Input editor, or use Sample, Upload file or Load URL.
  2. Press Convert. With Auto update on, the LESS output follows your edits.
  3. Review the nested LESS and add variables or mixins where values repeat.
  4. Use Copy or Download above the output panel to take the LESS file with you.

What the CSS to LESS converter does

Every CSS file is already valid LESS, so a CSS to LESS conversion is really about structure. This converter parses your stylesheet and groups rules that start with the same selector. .btn .icon moves inside .btn, .btn:focus-visible becomes a nested &:focus-visible, and the output uses LESS's brace syntax with 2-space indentation. Declarations, values and comments are kept exactly as they were.

Example

.btn{padding:8px}.btn.primary{background:#0f766e}.btn:focus-visible{outline:2px solid}.btn .icon{width:16px}@keyframes spin{from{transform:rotate(0)}to{transform:rotate(360deg)}}
.btn {
  padding: 8px;
  &:focus-visible {
    outline: 2px solid;
  }
  .icon {
    width: 16px;
  }
}

.btn.primary {
  background: #0f766e;
}

@keyframes spin {
  from {
    transform: rotate(0);
  }
  to {
    transform: rotate(360deg);
  }
}

The descendant .icon and the pseudo-class were nested. The compound selector .btn.primary was left as its own rule, because it is one element with two classes rather than a child of .btn; you can nest it as &.primary by hand if you prefer. @keyframes blocks are copied without nesting.

How the nesting is decided

For each rule, the converter splits the selector at its first combinator. The part before it (the first compound selector, such as .btn) becomes the parent, and the rest (.icon, > li or + .note) becomes a nested child. A selector without a combinator is split at its pseudo-class, so a:hover becomes &:hover inside a. Rules with the same parent are merged into one block, and a parent that ends up with a single child and no declarations of its own is collapsed back into one selector, so you never get empty wrapper blocks.

Making the most of LESS after converting

The converter does not invent variables or mixins; it cannot know which repeated values are meant to stay in sync. Good next steps are:

  • Replace repeated colors and sizes with variables: @brand: #0f766e; then background: @brand;.
  • Turn repeated declaration groups into mixins. In LESS any class can be reused as a mixin, so .btn(); inside another rule copies its declarations.
  • Use &:extend(.btn); when you want to share a selector instead of copying declarations.
  • Keep nesting to two or three levels so the compiled selectors stay short.

Things to check

  • Selector lists such as h1, h2 stay together as one rule and are not split.
  • Rules inside @media are nested within the media block, which stays at the top level; LESS also lets you move the media query inside the selector if you prefer that style.
  • Invalid CSS, like a missing }, stops the conversion with an error, so validate first with the CSS Validator if needed.

Prefer Sass? Use CSS to SCSS instead. To tidy the resulting file later, run it through the LESS Formatter. Conversion runs locally in your browser.

Frequently asked questions

Is my CSS already valid LESS?
Yes. LESS is a superset of CSS, so any valid stylesheet compiles unchanged. The converter only adds nesting to make the file easier to extend.
Does the converter create LESS variables?
No. It keeps all values as written. Add variables for colors and sizes you want to manage centrally after converting.
Why wasn’t .btn.primary nested under .btn?
The converter nests descendant, child and pseudo-class selectors. Compound selectors on the same element stay as separate rules; you can rewrite them as &.primary by hand.
Are comments preserved?
Yes. Block comments are kept in the output at the position where they appeared.

Last updated October 3, 2026

Related tools