1001Ferramentas
🔄Converters

CSS to SCSS Converter

Adapts CSS to SCSS preserving rules and turning CSS custom properties into SCSS variables when detected.

Swap custom properties for Sass variables

The part nobody mentions about migrating CSS to SCSS: there is barely a migration. Every valid CSS file is already valid SCSS, so renaming the extension is enough for the build to work. The real work is something else, and it is tedious: going through the file swapping custom properties, the double hyphen ones, for Sass dollar variables. That is precisely what this tool does, and all it does.

Two text substitutions, nothing more. A declaration starting with two hyphens followed by a colon and a value becomes the same line with a dollar sign, and every var call wrapping a custom property becomes the dollar reference. Everything else passes through untouched: selectors, media queries, comments. Two known catches: a var call with a fallback after the comma is not recognised and stays as is, and a declaration needs its closing semicolon to be detected.

What breaks the build later is scope. Your custom properties most likely live inside the root block; once they turn into dollar variables they are still in there, and a Sass variable declared inside a block only exists inside that block. Move the declarations to the top of the file or into a variables partial after converting. And do not convert what you change at runtime: class based themes, values that shift in a media query. Dollar dies at build time, double hyphen lives in the browser.

Frequently asked questions

Does it nest my selectors?
No. No rule is restructured. Selectors, media queries and comments come out exactly as they went in; only variables are touched.
Do I actually need to convert CSS to SCSS?
Usually not. Renaming the file to .scss already works, because CSS syntax is a subset of SCSS syntax. Converting only pays off when you want build time variables.
What about var calls with a fallback value?
They are not converted, because the pattern only recognises a var call containing just the property name. Fix those by hand and decide between the Sass variable and the fallback.

Related Tools