Girish Mahajan (Editor)

Stylus (stylesheet language)

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Designed by
  
TJ Holowaychuk

Typing discipline
  
dynamic

First appeared
  
2010

OS
  
Cross-platform

Stylus (stylesheet language)

Developer
  
LearnBoost (29 March 2011 - 26 March 2015) / Automattic (26 March 2015 - Present)

Stable release
  
0.53.0 / December 14, 2015 (2015-12-14)

Stylus is a dynamic stylesheet language that is compiled into Cascading Style Sheets (CSS). Its design is influenced by Sass and LESS. It's regarded as the fourth most used CSS preprocessor syntax. It was created by TJ Holowaychuk, a former programmer for Node.js and the creator of the Luna language. It is written in JADE and Node.js.

Contents

Selectors

Unlike CSS, which uses braces to open and close declaration blocks, indentation is used. Additionally, semi-colons (;) are optionally omitted. Hence, the following CSS:

can be shortened to:

Further, colons (:) and commas (,) are also optional; that means the above can be written as,

Variables

Stylus allows variables to be defined, however unlike LESS and Sass, it doesn't use a symbol to define variables. Additionally, variable assignment is done automatically by separating the property and keyword(s). In this way, variables are similar to the variables in Python.

The Stylus compiler would translate the above document to:

Mixins and functions

Both mixins and functions are defined in the same manner, but they are applied in different ways.

For example, if you wanted to define the CSS border radius property without having to use various Vendor Prefixes you can create:

then, to include this as a mixin, you would reference it as:

this would translate to:

Interpolation

To include variables in arguments and identifiers, brace characters surround the variable(s). For example,

evaluates to

References

Stylus (stylesheet language) Wikipedia