Sass_(stylesheet_language)

Sass (style sheet language)

Sass (style sheet language)

Stylesheet language


Sass (short for syntactically awesome style sheets) is a preprocessor scripting language that is interpreted or compiled into Cascading Style Sheets (CSS). SassScript is the scripting language itself.

Quick Facts Designed by, Developer ...

Sass consists of two syntaxes. The original syntax, called "the indented syntax," uses a syntax similar to Haml.[2] It uses indentation to separate code blocks and newline characters to separate rules. The newer syntax, SCSS (Sassy CSS), uses block formatting like that of CSS. It uses braces to denote code blocks and semicolons to separate rules within a block. The indented syntax and SCSS files are traditionally given the extensions .sass and .scss, respectively.

CSS3 consists of a series of selectors and pseudo-selectors that group rules that apply to them. Sass (in the larger context of both syntaxes) extends CSS by providing several mechanisms available in more traditional programming languages, particularly object-oriented languages, but that are not available to CSS3 itself. When SassScript is interpreted, it creates blocks of CSS rules for various selectors as defined by the Sass file. The Sass interpreter translates SassScript into CSS. Alternatively, Sass can monitor the .sass or .scss file and translate it to an output .css file whenever the .sass or .scss file is saved.[3]

The indented syntax is a metalanguage. SCSS is a nested metalanguage and a superset of CSS, as valid CSS is valid SCSS with the same semantics.

SassScript provides the following mechanisms: variables, nesting, mixins, and selector inheritance.[2]

History

Sass was initially designed by Hampton Catlin and developed by Natalie Weizenbaum.[4][5] After its initial versions, Weizenbaum and Chris Eppstein have continued to extend Sass with SassScript, a scripting language used in Sass files.

Major implementations

SassScript was implemented in multiple languages, the noteworthy implementations are:

  • The official open-source Dart implementation.[6]
  • The official "sass" node module on npm, which is Dart Sass compiled to pure JavaScript.[7]
  • The official "sass-embedded" node module which is a JavaScript wrapper around the native Dart executable.[8]
  • The original open-source Ruby implementation created in 2006,[6] since deprecated due to the lack of maintainers and reached End-of-Life in March 2019.[9][10]
  • libSass, the official open-source C++ implementation, deprecated in October 2020.[11]
  • The deprecated "node-sass" node module on npm, based on the deprecated libSass.[12]
  • JSass, an unofficial Java implementation,[13] based on the deprecated libSass.[14]
  • phamlp, an unofficial Sass/SCSS implementation in PHP.[6]
  • Vaadin has a Java implementation of Sass.[15]
  • Firebug, a Firefox XUL ("legacy") extension for web development.[16] It has been since deprecated in favor of developer tools integrated into Firefox itself. It stopped working since Firefox 57 dropped support for XUL extensions.

Features

Variables

Sass allows variables to be defined. Variables begin with a dollar sign ($). Variable assignment is done with a colon (:).[16]

SassScript supports four data types:[16]

  • Numbers (including units)
  • Strings (with quotes or without)
  • Colors (name, or names)
  • Booleans

Variables can be arguments to or results from one of several available functions.[17] During translation, the values of the variables are inserted into the output CSS document.[2]

More information SCSS, Compiled CSS ...

Nesting

CSS does support logical nesting, but the code blocks themselves are not nested. Sass allows the nested code to be inserted within each other.[2]

More information SCSS, Compiled CSS ...

More complicated types of nesting including namespace nesting and parent references are discussed in the Sass documentation.[16]

More information SCSS, Compiled CSS ...

Loops

Sass allows for iterating over variables using @for, @each and @while, which can be used to apply different styles to elements with similar classes or ids.

More information Compiled CSS ...

Arguments

Mixins also support arguments.[2]

More information Compiled CSS ...

In combination

More information Compiled CSS ...

Selector inheritance

While CSS3 supports the Document Object Model (DOM) hierarchy, it does not allow selector inheritance. In Sass, inheritance is achieved by inserting a line inside of a code block that uses the @extend keyword and references another selector. The extended selector's attributes are applied to the calling selector.[2]

More information Compiled CSS ...

Sass supports multiple inheritance.[16]

libSass

At the 2012 HTML5 Developer Conference, Hampton Catlin, the creator of Sass, announced version 1.0 of libSass, an open source C++ implementation of Sass developed by Catlin, Aaron Leung, and the engineering team at Moovweb.[18][19] Current Sass maintainer Chris Eppstein has expressed intent to contribute as well.[20]

According to Catlin, libSass can be "drop[ped] into anything and it will have Sass in it...You could drop it right into Firefox today and build Firefox and it will compile in there. We wrote our own parser from scratch to make sure that would be possible."[21]

The design goals of libSass are:

  • Performance – Developers have reported 10x speed up increases over the Ruby implementation of Sass.[22]
  • Easier integration – libSass makes it easier to integrate Sass into more software. Before libSass, tightly integrating Sass into a language or software product required bundling the entire Ruby interpreter. By contrast, libSass is a statically linkable library with zero external dependencies and C-like interface, making it easy to wrap Sass directly into other programming languages and tools. For example, open source libSass bindings now exist for Node, Go, and Ruby.[19]
  • Compatibility – libSass's goal is full compatibility with the official Ruby implementation of Sass. This goal has been achieved on libsass 3.3.[23]

IDE integration

See also


References

  1. "Dart Sass - latest release". github.com.
  2. Media Mark (3.2.12). "Sass - Syntactically Awesome Stylesheets". Sass-lang.com. Retrieved 2014-02-23.{{cite web}}: CS1 maint: numeric names: authors list (link)
  3. "Sass: Syntactically Awesome Style Sheets". sass-lang.com. Archived from the original on 2013-09-01.
  4. "Natalie Weizenbaum's blog". Archived from the original on 2007-10-11.
  5. "Sass / Scss". Drupal.org. 2009-10-21. Retrieved 2014-02-23.
  6. "sass". www.npmjs.com.
  7. "sass-embedded". www.npmjs.com.
  8. Weizenbaum, Natalie. "Ruby Sass Has Reached End-Of-Life « Sass Blog". sass.logdown.com. Retrieved 2019-04-21.
  9. "Sass: Ruby Sass". sass-lang.com. Retrieved 2019-04-21.
  10. "LibSass is Deprecated". sass-lang.com. 26 October 2020.
  11. "node-sass". www.npmjs.com.
  12. "JSass documentation". jsass.readthedocs.io.
  13. "SassCompiler (Vaadin 7.0.7 API)". Vaadin.com. 2013-06-06. Archived from the original on 2014-04-21. Retrieved 2014-02-23.
  14. H. Catlin (2012-10-15). "Hampton's 6 Rules of Mobile Design". HTML5 Developer Conference. Archived from the original on 2021-12-15. Retrieved 2013-07-11.
  15. M. Catlin (2012-04-30). "libsass". Moovweb Blog. Archived from the original on 2013-05-08. Retrieved 2013-07-11.
  16. A. Stacoviak & A. Thorp (2013-06-26). "Sass, libsass, Haml and more with Hampton Catlin". Archived from the original on 2013-08-06. Retrieved 2013-07-30.
  17. D. Le Nouaille (2013-06-07). "Sassc and Bourbon". Retrieved 2013-07-11.
  18. "Sass Compatibility". sass-compatibility.github.io. Retrieved 2019-11-29.

Share this article:

This article uses material from the Wikipedia article Sass_(stylesheet_language), and is written by contributors. Text is available under a CC BY-SA 4.0 International License; additional terms may apply. Images, videos and audio are available under their respective licenses.