CSS to LESS
Convert flat CSS into nested, readable LESS.
CSS to LESS Converter
Every CSS file is already valid LESS, so a "conversion" is really about structure: turning long, repetitive selectors into the nested blocks that make LESS pleasant to maintain. Paste your CSS and the converter groups rules that share a parent selector, moves pseudo-classes into &:hover blocks, and keeps child (>), sibling (+), and general sibling (~) combinators.
Example
.nav ul { list-style: none; }.nav a:hover { color: red; }
becomes
.nav {ul {list-style: none;}a {&:hover {color: red;}}}
How the nesting works
- Rules are grouped by their first compound selector –
.nav uland.nav liboth move into.nav. - Grouping repeats at every level, so deep selectors become deep nesting.
- Selector lists stay together unless every part shares the same parent (
.a h1, .a h2→.a { h1, h2 { } }). @media,@supports,@keyframes, and@font-faceblocks are preserved, and rules inside media queries are nested independently.- Comments are kept.
Turn off Nest selectors if you only want the code re-indented.
Next steps in LESS
After converting, introduce variables for repeated values – colors, spacing, breakpoints – and replace repeated declaration groups with mixins. After every conversion the page compiles your input and the result with the real compilers and compares the CSS, so you can see at a glance whether the translation is exact.
A note on order
Grouping moves rules next to related rules. Because CSS specificity is unchanged, this is safe for nearly all stylesheets; if your CSS relies on the source order of two equally specific selectors that target the same element, check that part after converting. To go back to CSS, press the swap button – it compiles the LESS with the official compiler.
Frequently Asked Questions
Is CSS valid LESS?
Yes. LESS is a superset of CSS, so any CSS file compiles unchanged. The converter adds nesting to make the code easier to maintain.
Does the converter create LESS variables automatically?
No. It restructures selectors but keeps your values as written, because guessing which values belong together can break designs. Replace repeated values with @variables afterwards.
Will nesting change how my styles apply?
The compiled selectors are identical to your original ones; the built-in check compiles the LESS and compares it with your CSS.