Skip to content

Menu

CSS to SCSS Converter

Convert plain CSS to SCSS with nesting

Runs entirely in your browserConvertersFree, no sign-up
Loading tool

01What is CSS to SCSS Converter?

Moving an old stylesheet into Sass usually starts with an hour of cutting rules and pasting them inside their parents. This converter does that first pass for you. Paste flat CSS and you get SCSS with related selectors nested under the rule they extend. It works in three steps. A small parser strips comments, then reads each rule as a selector plus a list of declarations. Declarations are split on semicolons only outside quotes and parentheses, so a data: URI or a content: "a;b" string survives in one piece. Next, for every rule, it scans the rules that come after it. A later selector that starts with the parent plus a space becomes a plain nested block, so .card .title sits inside .card as .title. A child combinator works the same way and gives > .icon. Pseudo-classes, pseudo-elements, compound classes and BEM suffixes get the & parent selector instead: .card:hover becomes &:hover, .btn.active becomes &.active, and .card__header becomes &__header. That & matters, because Sass nesting without it means a descendant. Finally it prints the tree with two-space indentation. A few rules keep the output honest. Nesting is one level deep, so .navbar .nav-item:hover lands under .navbar as .nav-item:hover, not inside a nested .nav-item block. Only rules that come after their parent are pulled in. If .item .label appears before .item, both stay flat. Selector lists like h1, h2 are never nested, because putting h1 span under that list would also produce h2 span. At-rules get their own handling. @import and @charset statements move to the top. Blocks like @font-face, @keyframes and @supports are copied through unchanged after the nested rules. Rules inside @media are grouped by query and written as separate @media blocks at the very end, not nested inside each selector. Comments are dropped, including an unclosed one at the end of the input. The main thing to watch is the cascade. Nesting pulls child rules up next to their parent and moves media blocks to the end. With equal specificity, a different rule can then win. Compile the result and diff it against your original CSS before you commit. Think of this as a head start on a refactor, not a formatter, and expect to tidy by hand.

Front-end developers moving a flat stylesheet into Sass use it to get the first round of nesting done before they refine it by hand. The tool runs entirely in your browser, so your data never leaves your device.

02How to use CSS to SCSS Converter

  1. Paste your stylesheet into CSS Input, or load an example such as Flat selectors, BEM-style classes or Media queries
  2. Read the nested result in SCSS Output and check the character counts for both panes
  3. Look at the @media blocks at the bottom and move them inside selectors by hand if your team prefers that style
  4. Click Copy SCSS to copy the result, or Reset to clear the input

03Worked examples

Input: .card { padding: 1rem; } .card .title { font-weight: 600; } .card:hover { box-shadow: none; }
Result: .card { padding: 1rem; .title { font-weight: 600; } &:hover { box-shadow: none; } }
A descendant rule nests as-is, but a pseudo-class on the parent needs & so it compiles back to .card:hover and not .card :hover.
Input: .btn { color: red; } .btn > .icon { margin: 0; } .btn.active { color: blue; }
Result: .btn { color: red; > .icon { margin: 0; } &.active { color: blue; } }
The child combinator stays at the start of the nested selector, and the compound .btn.active becomes &.active.
Input: .card { padding: 1rem; } .card__header { font-weight: bold; } .card--featured { border: 2px solid #3498db; }
Result: .card { padding: 1rem; &__header { font-weight: bold; } &--featured { border: 2px solid #3498db; } }
BEM element and modifier suffixes are nested with &.
Input: @import url("base.css"); .icon { background: url(data:image/svg+xml;utf8,<svg/>); content: "a;b"; } @keyframes spin { to { transform: rotate(1turn); } } .icon:hover { opacity: .8; }
Result: @import url("base.css"); .icon { background: url(data:image/svg+xml;utf8,<svg/>); content: "a;b"; &:hover { opacity: .8; } } @keyframes spin { to { transform: rotate(1turn); } }
Semicolons inside url() and quotes don't split declarations. @import goes first and @keyframes is copied through after the rules.
Input: .nav a { color: #333; } @media (max-width: 600px) { .nav a { color: #000; } }
Result: .nav a { color: #333; } @media (max-width: 600px) { .nav a { color: #000; } }
Rules inside a media query stay in their own @media block at the end.
Input: h1, h2 { margin: 0; } h1 span { color: red; }
Result: h1, h2 { margin: 0; } h1 span { color: red; }
h1 span is not nested under the h1, h2 list, because that would also produce h2 span.

04Common use cases

  • Starting a migration of a legacy stylesheet into the Sass pipeline of an Angular or Rails app
  • Grouping BEM rules like .card__header and .card--featured into one nested .card block
  • Moving styles copied from browser DevTools into a .scss partial without retyping the nesting
  • Showing a junior developer the difference between a nested .title and a nested &:hover
  • Getting a quick first draft of a component's SCSS before cleaning it up by hand
  • Checking whether a set of flat rules nests cleanly or is full of selector lists that won't

05Tips

  • Put parent rules before their children in the input. A child that appears first won't be nested.
  • Split selector lists into separate rules first if you want them nested. The tool skips any rule containing a comma.
  • Keep a copy of your comments, because the parser drops all of them.
  • Compile the SCSS and diff it against the original CSS. Moving rules can change which one wins when specificity is equal.

06Related concepts

SCSS, Sass nesting, parent selector &, BEM, media queries.

Frequently Asked Questions

What is CSS to SCSS Converter?

CSS to SCSS Converter is a free, browser-based developer tool on AIDToolStack. Convert plain CSS to SCSS with nesting It requires no installation or sign-up and works entirely in your browser.

Is CSS to SCSS Converter free to use?

Yes. No sign-up, no fees and no usage cap.

Does CSS to SCSS Converter store my data?

No. It runs in your browser; nothing is uploaded.

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe