Less (stylesheet language)
![]() |
|
Designed by | Alexis Sellier |
---|---|
Developer | Alexis Sellier, Dmitry Fadeyev |
Appeared in | 2009 |
Stable release | 2.0.0[1] / November 9, 2014 |
Typing discipline | dynamic |
Influenced by | CSS, Sass |
Influenced | Sass, Less Framework |
OS | Cross-platform |
License | Apache License 2 |
Filename extension(s) | .less |
Website | lesscss.org |
Less (also known as LESS) is a dynamic stylesheet language designed by Alexis Sellier. It is influenced by Sass and has influenced the newer "SCSS" syntax of Sass, which adapted its CSS-like block formatting syntax.[2] Less is open-source. Its first version was written in Ruby, however in the later versions, use of Ruby has been deprecated and replaced by JavaScript. The indented syntax of Less is a nested metalanguage, as valid CSS is valid Less code with the same semantics. Less provides the following mechanisms: variables, nesting, mixins, operators and functions; the main difference between Less and other CSS precompilers being that Less allows real-time compilation via less.js by the browser.[3][4] Less can run on the client-side and server-side,[4] or can be compiled into plain CSS.
Contents
Variables[edit]
Less allows variables to be defined. Less variables are defined with an at sign(@). Variable assignment is done with a colon (:).
During translation, the values of the variables are inserted into the output CSS document.[4]
@color: #4D926F; #header { color: @color; } h2 { color: @color; }
The code above in Less would compile to the following CSS code.
#header { color: #4D926F; } h2 { color: #4D926F; }
Mixins[edit]
Mixins allow embedding all the properties of a class into another class by including the class name as one of its properties, thus behaving as a sort of constant or variable. They can also behave like functions, and take arguments. CSS does not support Mixins. Any repeated code must be repeated in each location. Mixins allow for more efficient and clean code repetitions, as well as easier alteration of code.[4]
.rounded-corners (@radius: 5px) { -webkit-border-radius: @radius; -moz-border-radius: @radius; border-radius: @radius; } #header { .rounded-corners; } #footer { .rounded-corners(10px); }
The above code in Less would compile to the following CSS code:
#header { -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; } #footer { -webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10px; }
Less has a special type of ruleset called parametric mixins which can be mixed in like classes, but accepts parameters.
Nesting[edit]
CSS supports logical nesting, but the code blocks themselves are not nested. Less allows nesting of selectors inside other selectors. This makes inheritance clear and style sheets shorter.[4]
#header { h1 { font-size: 26px; font-weight: bold; } p { font-size: 12px; a { text-decoration: none; &:hover { border-width: 1px; } } } }
The above code in Less would compile to the following CSS code:
#header h1 { font-size: 26px; font-weight: bold; } #header p { font-size: 12px; } #header p a { text-decoration: none; } #header p a:hover { border-width: 1px; }
Functions and operations[edit]
Less allows operations and functions. Operations allow addition, subtraction, division and multiplication of property values and colors, which can be used to create complex relationships between properties. Functions map one-to-one with JavaScript code, allowing manipulation of values.
@the-border: 1px; @base-color: #111; @red: #842210; #header { color: @base-color * 3; border-left: @the-border; border-right: @the-border * 3; } #footer { color: @base-color + #003300; border-color: desaturate(@red, 10%); }
The above code in Less would compile to the following CSS code:
#header { color: #333; border-left: 1px; border-right: 3px; } #footer { color: #114411; border-color: #7d2717; }
Comparison[edit]
Sass[edit]
Both Sass and Less are CSS preprocessors, which allow writing clean CSS in a programming construct instead of static rules.[5]
As of Less 1.4, Less supports nested, inherited rules via the &:extends
and @extends
pseudo-selector. Prior to this, a main difference between Less and other preprocessors like Sass was the lack of an @extends
directive to support inheritance of rules across classes, leading to cleaner CSS with less duplication.
LESS is inspired by Sass.[6] Sass was designed to both simplify and extend CSS, so things like curly braces were removed from the syntax. Less was designed to be as close to CSS as possible, so the syntax is identical to existing CSS code. As a result, existing CSS can be used as valid Less code.
The newer versions of Sass also introduced a CSS-like syntax called SCSS (Sassy CSS).[2]
For more syntax comparisons, see https://gist.github.com/674726.
Use on sites[edit]
Less can be applied to sites in a number of ways. One option is to include the less.js JavaScript file to convert the code on-the-fly. The browser then renders the output CSS. Another option is to render the Less code into pure CSS and upload the CSS to a site. With this option no .less files are uploaded and the site does not need the less.js JavaScript converter.
Less software[edit]
Name | Description | Software License | Platform | Functionality |
---|---|---|---|---|
WinLess | GUI LESS Compiler | Apache 2.0[7] | Windows | Compiler |
Crunch | LESS editor and compiler (requires Adobe AIR) | GPL[8] | Windows, Mac OS X | Compiler Editor |
less.js-windows | Simple command-line utility for Windows that will compile *.less files to CSS using less.js. | MIT_License[9] | Windows | Compiler |
less.app | LESS Compiler | Proprietary | Mac OS X | Compiler |
CodeKit | LESS Compiler | Proprietary | Mac OS X | Compiler |
LessEngine | LESS Compiler | Free | OpenCart Plugin | Compiler |
SimpLESS | LESS Compiler | free but no explicit license[10] | Windows Mac OS X Linux |
Compiler |
Chirpy | Compiles various JavaScript and CSS extension languages, including LESS | Ms-PL[11] | Visual Studio Plugin | Compiler |
Mindscape Web Workbench | Syntax highlighting and Intellisense for LESS (also Sass and CoffeeScript) | Proprietary | Visual Studio Plugin | Compiler Syntax Highlighting |
Eclipse Plugin for LESS | Eclipse Plugin | EPL 1.0[12] | Eclipse Plugin | Syntax highlighting Content assist |
mod_less | Apache2 module to compile LESS on the fly | Open Source | Linux | Compiler |
grunt-contrib-less | Node.js Grunt task to convert less to css files | Open Source | Node.js | Compiler |
See also[edit]
References[edit]
- ^ https://github.com/less/less.js/blob/master/CHANGELOG.md
- ^ a b Sass and Less Sass and Less
- ^ http://stackoverflow.com/questions/4436643/is-there-a-sass-js-something-like-less-js
- ^ a b c d e Official Less website Official Less website
- ^ What's Wrong With CSS What's Wrong With CSS
- ^ About Less About
- ^ [1] WinLess github Issue "License Information"
- ^ Crunch's LICENSE.txt at github Crunch's LICENSE.txt at github
- ^ [2] github license
- ^ [3] license file at github (placeholder)
- ^ [4] Chirpy License Information at CodePlex
- ^ Eclipse Plugin for LESS homepage Eclipse Plugin for LESS homepage
External links[edit]
- Official Less website
- Less source code repository (Git)
- LESS Hat mixins library
- Sai the mixins extension and CSS authoring framework for LESS & SASS/SCSS (Git)
|