1 # SugarSS [![Build Status][ci-img]][ci]
3 <img align="right" width="120" height="155"
4 title="SugarSS logo by Maria Keller"
5 src="http://postcss.github.io/sugarss/logo.svg">
7 Indent-based CSS syntax for [PostCSS].
15 box-shadow: 1px 0 9px rgba(0, 0, 0, .4),
16 1px 0 3px rgba(0, 0, 0, .6)
19 @media (max-width: 400px)
24 As any PostCSS custom syntax, SugarSS has source map, [stylelint]
25 and [postcss-sorting] support out-of-box.
27 It was designed to be used with [PreCSS] and [postcss-nested-props].
28 But you can use it with any PostCSS plugins
29 or use it without any PostCSS plugins.
30 With [gulp-sass-to-postcss-mixins] you can use `+mixin` syntax as in Sass.
32 <a href="https://evilmartians.com/?utm_source=sugarss">
33 <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg"
34 alt="Sponsored by Evil Martians" width="236" height="54">
37 [gulp-sass-to-postcss-mixins]: https://github.com/akella/gulp-sass-to-postcss-mixins
38 [postcss-nested-props]: https://github.com/jedmao/postcss-nested-props
39 [postcss-sorting]: https://github.com/hudochenkov/postcss-sorting
40 [stylelint]: http://stylelint.io/
41 [PostCSS]: https://github.com/postcss/postcss
42 [PreCSS]: https://github.com/jonathantneal/precss
43 [ci-img]: https://img.shields.io/travis/postcss/sugarss.svg
44 [ci]: https://travis-ci.org/postcss/sugarss
48 SugarSS MIME-type is `text/x-sugarss` with `.sss` file extension.
52 We recommend 2 spaces indent. However, SugarSS autodetects indent
53 and can be used with tabs or spaces.
55 But it is prohibited to mix spaces and tabs in SugarSS sources.
59 SugarSS was designed to have intuitively multiline selectors and declaration
62 There are 3 rules for any types of nodes:
65 // 1. New line inside brackets will be ignored
66 @supports ( (display: flex) and
69 // 2. Comma at the end of the line
70 @media (max-width: 400px),
73 // 3. Backslash before new line
78 In selector you can put a new line anywhere. Just keep same indent
79 for every line of selector:
87 In declaration value you can put new line anywhere. Just keep bigger indent
92 background: linear-gradient(rgba(0, 0, 0, 0), black)
93 linear-gradient(red, rgba(255, 0, 0, 0))
97 linear-gradient(rgba(0, 0, 0, 0), black)
98 linear-gradient(red, rgba(255, 0, 0, 0))
103 SugarSS supports two types of comments:
113 There is no “silent” comments in SugarSS. Output CSS will contain all comments
114 from `.sss` source. But you can use [postcss-discard-comments]
115 for Sass’s silent/loud comments behaviour.
117 [postcss-discard-comments]: https://www.npmjs.com/package/postcss-discard-comments
119 ### Rule and Declarations
121 SugarSS separates selectors and declarations by `:\s` or `:\n` token.
123 So you must write a space after property name: `color: black` is good,
124 `color:black` is prohibited.
128 * SublimeText: [Syntax Highlighting for .SSS SugarSS]
129 * Atom: [language-postcss], [source-preview-postcss] and [build-sugarss]
132 We are working on syntax highlight support in text editors.
134 Right now, you can set `Sass` or `Stylus` syntax highlight for `.sss` files.
136 [Syntax Highlighting for .SSS SugarSS]: https://packagecontrol.io/packages/Syntax%20Highlighting%20for%20SSS%20SugarSS
137 [source-preview-postcss]: https://atom.io/packages/source-preview-postcss
138 [language-postcss]: https://atom.io/packages/language-postcss
139 [build-sugarss]: https://atom.io/packages/build-sugarss
140 [vim-sugarss]: https://github.com/hhsnopek/vim-sugarss
144 Install SugarSS via npm:
147 npm install sugarss --save-dev
152 Just set SugarSS to PostCSS `parser` option and PostCSS will compile
155 [Gulp](https://github.com/postcss/gulp-postcss):
158 var sugarss = require('sugarss');
159 var postcss = require('gulp-postcss');
160 var rename = require('gulp-rename');
162 gulp.task('style', function () {
163 return gulp.src('src/**/*.sss')
164 .pipe(postcss(plugins, { parser: sugarss }))
165 .pipe(rename({ extname: '.css' }))
166 .pipe(gulp.dest('build'));
170 [Webpack](https://github.com/postcss/postcss-loader):
177 loader: "style-loader!css-loader!postcss-loader?parser=sugarss"
183 [CLI](https://github.com/postcss/postcss-cli):
186 postcss -u autoprefixer -p sugarss test.sss -o test.css
189 ### SugarSS to SugarSS
191 Sometimes we use PostCSS not to build CSS, but to fix source file.
192 For example, to sort properties by [postcss-sorting].
194 For this cases, use `syntax` option, instead of `parser`:
197 gulp.task('sort', function () {
198 return gulp.src('src/**/*.sss')
199 .pipe(postcss([sorting], { syntax: sugarss }))
200 .pipe(gulp.dest('src'));
204 [postcss-sorting]: https://github.com/hudochenkov/postcss-sorting
208 You can even compile existed CSS sources to SugarSS syntax.
209 Just use `stringifier` option instead of `parser`:
212 postcss().process(css, { stringifier: sugarss }).then(function (result) {
213 result.content // Converted SugarSS content
219 [postcss-import] doesn’t support `.sss` file extension, because this plugin
220 implements W3C specification. If you want smarter `@import`, you should
221 use [postcss-easy-import] with `extensions` option.
224 var postcssPlugin = [
225 easyImport({ extensions: ['.sss'] })
229 [postcss-easy-import]: https://github.com/TrySound/postcss-easy-import
230 [postcss-import]: https://github.com/postcss/postcss-import
234 Cute project logo was made by [Maria Keller](http://www.mariakellerac.com/).