36

Is there any code beautifier formatter for Sass (SCSS) code? I know how to format the output CSS code generated by SCSS compiler but how to give nice auto formatting to SCSS code itself?

I've tried some online CSS formatter but they don't work with SCSS code.

If i give this to them

.list5 {  
    border-bottom: 1px solid #f2f2f1;
    padding: 0 0 20px 0;
    margin: 0 0 20px 0;
ul li {
    margin: 0 0 5px 25px !important;
    height: auto !important;
    background: none !important;
    font-size: 14px;
    padding: 18px 3px 5px !important;
    width: 169px !important; }
 }

they give this output

.list5 {
    border-bottom: 1px solid #f2f2f1;
    padding: 0 0 20px 0;
    margin: 0 0 20px 0;
    margin: 0 0 5px 25px !important;
    height: auto !important;
    background: none !important;
    font-size: 14px;
    padding: 18px 3px 5px !important;
    width: 169px !important;
}

which remove this part ul li {}

seven-phases-max
  • 11,765
  • 1
  • 45
  • 57
Jitendra Vyas
  • 148,487
  • 229
  • 573
  • 852

5 Answers5

74

Online

Paste your CSS/SCSS/LESS into dirtystylesheet.com and hit Clean

Via Command Line

Via command line you can re-format CSS/SCSS/Sass using the sass-convert script:

$ sass-convert messy.scss clean.scss

or CSS to SCSS:

$ sass-convert messy.css clean.scss

or SCSS to Sass:

$ sass-convert messy.scss clean.sass

The sass-convert script is installed when you install Sass. It can convert any direction between: css, scss, and sass.

Learn more about sass-convert:

Advanced user tip: Because the sass syntax is much stricter (only allowing one property: value pair per line) you're less likely to run into an issue with messy code.

Beau Smith
  • 33,433
  • 13
  • 94
  • 101
11

http://hilite.me/ - supports Sass and Scss

JSFiddle will do the trick as well. Just hit the TidyUp button

Jason
  • 296
  • 2
  • 8
2

Pretty Diff will strip the "$" from your variables.

You can try: http://www.prettyprinter.de/

It's not perfect but at least it indents an extra level for nested rules and from what I've seen keeps all the scss stuff untouched (.ie does not strip it out).

Regards

ziku
  • 69
  • 1
1

If you use sublime text I can recommend SassBeautify to quickly format any sass/scss https://packagecontrol.io/packages/SassBeautify

richimgd
  • 105
  • 1
  • 8
1

I ran the code through Pretty Diff and I got this output:

.list5 {
    border-bottom:1px solid #f2f2f1;
    padding:0 0px 20px 0px;
    margin:0 0px 20px 0px;
    ul li {
        background: none !important;
        font-size: 14px;
        height: auto !important;
        margin: 0px 0px 5px 25px !important;
        padding: 18px 3px 5px !important;
        width: 169px !important;
    }
}

Is that what you are looking for? It looks strange for CSS.

austincheney
  • 1,189
  • 9
  • 11