Title

Description

Try Stylus!

Stylus is an innovative stylesheet language that compiles down to CSS. Inspired by SASS, Stylus is built with node.js and capable of running in the browser as this interactive tutorial illustrates. Edit the Stylus source on the left to see the resulting changes appear in the CSS on the right.

Nesting

Selector nesting enables you to keep your styles DRY:

Flexible syntax

Semi-colons, colons, and braces are optional:

Parent reference

The parent reference operator inspired by SASS is also available:

Mixins

Stylus mixins allow you to define reusable functionality by defining in-language functions which can be called from within blocks:

Transparent mixins

Transparent mixins are unique to Stylus, and are an incredibly powerful way to enhance your stylesheets. Here all the arguments passed are simply assigned to three properties. Note that parenthesis are not required, making it easy to provide cross-browser support to properties like opacity, border-radius, and even gradients.

Variables

Stylus variables behave as you would expect in any other language, and may optionally be prefixed by the “$” character:

Block property access

Stylus property access provides easy access to values defined within the current block. Simply prefix the name of the property with “@” to reference the value.

Robust feature-rich language

Stylus is not just a pre-processor, it’s a flexible and powerful language. Combined with the concept of transparent mixins you can create robust cross-browser support, or simply make your life easier with customized CSS properties as shown below:

Iteration

List iteration with Stylus is simple:

Interpolation

Interpolation combined with other powerful features allow you to mold properties and selectors all within the language itself.

Operators

Stylus supports all the operators you’ve come to expect from a language, as well as some specific to Stylus.

Type coercion

Stylus performs type coercion when appropriate, and supports all of the unit types you’ve come to know and love.

The sprintf operator

The powerful “%” operator when used with strings behaves like sprintf, with each argument compiled through the stylus compiler, producing a literal value.

Color operations

Operations against colors are especially useful. When adding or subtracting by a percentage the color lightness may be adjusted, or the hue may be adjusted with deg:

Functions

Stylus functions may be defined in the same manner as mixins, however their usage differs as they return values. For example you could define a sum function as shown below:

Keyword arguments

Keyword arguments are also supported to make function invocation more expressive, also allowing you to disregard argument ordering.

Built-in functions

Stylus is packed with over 60 built-in functions for manipulating colors, checking variable types, math, list operations, and more, many of which are defined in the Stylus language itself.

Color BIFs

The Color built-in functions allow you adjust lightness, hue, and saturation, check if colors are light or dark and more.

End

That’s it for now! To view the rest of the powerful features Stylus provides click “View Documentation” in the corner.