CSS to Less Converter
Convert CSS code to Less with nesting
Input CSS
Converted Less
Paste your CSS on the left and the less shows up here.
Or drop a file on this box, , or .
What is CSS to LESS Conversion?
Tired of writing the same CSS selectors over and over? This tool converts your plain CSS into LESS (Leaner Style Sheets) format with proper nesting. Instead of repeating parent selectors across your stylesheet, LESS lets you nest child selectors within parents - making your code cleaner, shorter, and easier to maintain.
LESS is a CSS preprocessor that extends the language with variables, mixins, functions, and most importantly - nesting. Our converter takes your flat CSS rules and reorganizes them into nested LESS syntax automatically. This gives you a perfect starting point for modernizing your stylesheets and gradually adding LESS features like variables and reusable mixins.
Rules that start with the same selector and sit next to each other share one block, and every rule stays where it was in the file, so the cascade is untouched. Rules inside media queries are nested the same way inside their @media block, a selector list like h1, h2 is kept as one rule, and @keyframes or @font-face blocks are copied across as written. The conversion runs in your browser, with nothing uploaded.
How to Use the CSS to Less Converter
The Less panel rebuilds itself on every edit. The nesting is decided by the first compound selector of each rule (.card in .card .badge), one level deep, and only for rules that follow each other.
Paste, Upload, or Load Sample
Paste flat CSS into Input CSS or load a file with Upload. Sample fills in a card, its badge and the badge's hover state, which shows the nesting off nicely. Descendant selectors that share a first part, like this sidebar, are the input it handles best:
.sidebar {
width: 280px;
}
.sidebar .nav-link {
color: #37474f;
}
.sidebar .nav-link.active {
font-weight: 600;
} View Converted Less
The right Converted Less panel shows the nested version as you type. .card:hover stays one selector, while .card :hover (any hovered element inside the card) nests as :hover under .card, which compiles back to the same descendant selector. A missing brace shows an error above the editor instead of half a file.
Copy or Download
Copy the Less or Download it as converted.less, then compile it once and diff the result against your original stylesheet before you swap files. Clear empties both editors.
When You'd Actually Use This
Modernizing Legacy Stylesheets
Got old CSS files written before you adopted LESS or SCSS? Convert them in seconds to take advantage of preprocessor features with Webpack or Gulp. This modernizes your codebase without rewriting everything from scratch.
Migrating to LESS
Planning to move your project from plain CSS to LESS? This tool handles the structural conversion automatically. Once converted, you can gradually add variables, mixins, and LESS-specific features to improve maintainability.
Team Standardization
Different team members might have written CSS in different ways. Converting to LESS enforces consistent nesting patterns and helps standardize your stylesheet structure across the entire project.
Reducing Code Duplication
LESS nesting eliminates repeated parent selectors, making your code more DRY (Don't Repeat Yourself). After conversion, the nested structure makes it easier to identify and extract reusable mixins.
Common Questions
Will my CSS be exactly the same after conversion?
It should be. Less compiles .card { .badge { } } straight back to .card .badge, and a selector written twice comes out as two rules in its original position, so nothing is merged or dropped. We check this by compiling the output with Less and comparing the rule list against the input. Comments between declarations are kept; a comment inside a selector is dropped, just as the browser ignores it.
Does it handle media queries?
Yes. An @media, @supports or @container block stays where it was, and the rules inside it are nested like any others. What it does not do is move a media query inside the selector it affects, which Less allows; that is a style choice worth making by hand once the file is in Less.
What about pseudo-selectors like :hover?
A rule like .card .badge:hover lands under .card as .badge:hover. A plain .badge:hover stays a top-level rule instead of becoming &:hover inside .badge, so fold those in yourself if you want them nested. The space matters: .card :hover means a hovered descendant and is kept that way.
Can I use the converted LESS immediately?
Usually. Plain CSS is close to valid Less already, and the nesting adds nothing Less cannot read. One case to watch: Less reads @{name} inside a quoted string as a variable, so content: "@{x}" fails with variable @x is undefined. Compile it once before you swap files.
How do I add variables after conversion?
Once you have valid LESS code, look for repeated values (colors, font sizes, etc.) and replace them with LESS variables. For example, replace #333333 with @dark-color throughout your file. Check LESS documentation for variable syntax.
Is my CSS data stored anywhere?
No. The nesting is worked out by this page's script in your browser, and the stylesheet is neither uploaded nor kept.