Menu
Home Explore People Places Arts History Plants & Animals Science Life & Culture Technology
On this page
Less (style sheet language)
Dynamic stylesheet language

Less (Leaner Style Sheets; sometimes stylized as LESS) is a dynamic preprocessor style sheet language that can be compiled into Cascading Style Sheets (CSS) and run on the client side or server side. Designed by Alexis Sellier, Less is influenced by Sass and has influenced the newer "SCSS" syntax of Sass, which adapted its CSS-like block formatting syntax. Less is an open source project. 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 is that Less allows real-time compilation via less.js by the browser.

Related Image Collections Add Image
We don't have any YouTube videos related to Less (style sheet language) yet.
We don't have any PDF documents related to Less (style sheet language) yet.
We don't have any Books related to Less (style sheet language) yet.
We don't have any archived web articles related to Less (style sheet language) yet.

Features

Variables

Less allows variables to be defined. Variables in Less 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.5

@pale-green-color: #4D926F; #header { color: @pale-green-color; } h2 { color: @pale-green-color; }

The code above in Less would compile to the following CSS code.

#header { color: #4D926F; } h2 { color: #4D926F; }

Mixins

Mixins allows embedding all the properties of a class into another class by including the class name as one of its property, 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 allows for more efficient and clean code repetitions, as well as easier alteration of code.6

.rounded-corners (@radius: 5px 10px 8px 2px) { -webkit-border-radius: @radius; -moz-border-radius: @radius; border-radius: @radius; } #header { .rounded-corners; } #footer { .rounded-corners(10px 25px 35px 0px); }

The above code in Less would compile to the following CSS code:

#header { -webkit-border-radius: 5px 10px 8px 2px; -moz-border-radius: 5px 10px 8px 2px; border-radius: 5px 10px 8px 2px; } #footer { -webkit-border-radius: 10px 25px 35px 0px; -moz-border-radius: 10px 25px 35px 0px; border-radius: 10px 25px 35px 0px; }

Less has a special type of ruleset called parametric mixins which can be mixed in like classes, but accepts parameters.

#header { h1 { font-size: 26px; font-weight: bold; } p { font-size: 16px; a { text-decoration: none; color: red; &:hover { border-width: 1px; color: #fff; } } } }

The above code in Less would compile to the following CSS code:

#header h1 { font-size: 26px; font-weight: bold; } #header p { font-size: 16px; } #header p a { text-decoration: none; color: red; } #header p a:hover { border-width: 1px; color: #fff; }

Functions and operations

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

Sass

Both Sass and Less are CSS preprocessors, which allow writing clean CSS in a programming construct instead of static rules.7

Less is inspired by Sass.89 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, and as a result existing CSS can be used as valid Less code.10

The newer versions of Sass also introduced a CSS-like syntax called SCSS (Sassy CSS).

Use on sites

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

NameDescriptionSoftware LicensePlatformFunctionality
WinLess - Windows GUI for less.jsGUI Less CompilerApache 2.011WindowsCompiler
CrunchLess editor and compiler (requires Adobe AIR)GPL12Windows, Mac OS XCompilerEditor
less.js-windowsSimple command-line utility for Windows that will compile *.less files to CSS using less.js.MIT License13WindowsCompiler
less.appLess CompilerProprietaryMac OS XCompiler
CodeKitLess CompilerProprietaryMac OS XCompiler
LessEngineLess CompilerFreeOpenCart PluginCompiler
SimpLESSLess Compilerfree but no explicit license14WindowsMac OS XLinuxCompiler
ChirpyLess CompilerMs-PL15Visual Studio PluginCompiler
Mindscape Web WorkbenchSyntax highlighting and IntelliSense for Less and SassProprietaryVisual Studio PluginCompilerSyntax Highlighting
Eclipse Plugin for LessEclipse PluginEPL 1.016Eclipse PluginSyntax highlightingContent assistCompiler
mod_lessApache2 module to compile Less on the flyOpen SourceLinuxCompiler
grunt-contrib-lessNode.js Grunt task to convert Less to CSSMIT17Node.jsCompiler
Web EssentialsVisual Studio extension with support for Less and SassApache 2.0 18WindowsSyntax highlighting, Content assist, Compiler
clesscPure C++ compilerMIT19at least Windows, Linux, MacOSCompiler
Less WebCompilerWeb-based compilerMIT20at least Windows, Linux, MacOSCompiler, Syntax highlighting, Minifier

See also

References

  1. The Core Less Team. "Getting started | Less.js". Less.js. Retrieved 2021-03-19. http://lesscss.org/

  2. Weizenbaum, Nathan (2009-06-17). "Sass and Less : Nex3". Archived from the original on 2009-06-21. Retrieved 2021-03-19. https://web.archive.org/web/20090621074106/http://nex-3.com/posts/83-sass-and-less

  3. The Core Less Team. "Getting started | Less.js". Less.js. Retrieved 2021-03-19. http://lesscss.org/

  4. Meng, Jiew (2010-12-14). Mortensen, Peter (ed.). "css - Is there a SASS.js? Something like LESS.js?". Stack Overflow. Retrieved 2021-03-19. https://stackoverflow.com/questions/4436643/is-there-a-sass-js-something-like-less-js

  5. The Core Less Team. "Getting started | Less.js". Less.js. Retrieved 2021-03-19. http://lesscss.org/

  6. The Core Less Team. "Getting started | Less.js". Less.js. Retrieved 2021-03-19. http://lesscss.org/

  7. Atwood, Jeff (2010-04-30). "What's Wrong With CSS". Coding Horror. Retrieved 2022-12-03. https://blog.codinghorror.com/whats-wrong-with-css/

  8. The Core Less Team. "About | Less.js". Less.js. Retrieved 2021-03-19. http://lesscss.org/about/

  9. Weizenbaum, Nathan (2009-06-17). "Sass and Less : Nex3". Archived from the original on 2009-06-21. Retrieved 2021-03-19. https://web.archive.org/web/20090621074106/http://nex-3.com/posts/83-sass-and-less

  10. Eppstein, Chris (2010-11-10). "sass_and_less_compared.markdown". GitHub Gist. Retrieved 2021-03-19. https://gist.github.com/674726

  11. Lagendijk, Mark (2013-01-29). "License Information · Issue #55 · marklagendijk/WinLess". GitHub. Retrieved 2021-03-19. https://github.com/marklagendijk/WinLess/issues/55#issuecomment-12863789

  12. Dean, Matthew (2011-12-02). "Crunch/LICENSE.txt at master · matthew-dean/Crunch". GitHub. Retrieved 2021-03-19. https://github.com/matthew-dean/Crunch/blob/master/LICENSE.txt

  13. Smart, Duncan (2013-07-25). "less.js-windows/LICENSE at master · duncansmart/less.js-windows". GitHub. Retrieved 2021-03-19. https://github.com/duncansmart/less.js-windows/blob/master/LICENSE

  14. Engel, Christian (2012-07-29). "SimpLESS/LICENSE.txt at master · Paratron/SimpLESS". GitHub. Retrieved 2021-03-19. https://github.com/Paratron/SimpLESS/blob/master/LICENSE.txt

  15. Evan Nagle. "Chirpy - VS Add In For Handling Js, Css, DotLess, and T4 Files - CodePlex Archive". CodePlex. Archived from the original on 2021-02-20. Retrieved 2021-03-19. https://web.archive.org/web/20210220115440/https://archive.codeplex.com/?p=chirpy

  16. Vincent Simonet. "Eclipse plugin for LESS". normalesup.org. Retrieved 2021-03-19. http://www.normalesup.org/~simonet/soft/ow/eclipse-less.html

  17. Kellen, Tyler (2012-09-04). "grunt-contrib-less/LICENSE-MIT at master · gruntjs/grunt-contrib-less". GitHub. Retrieved 2021-03-19. https://github.com/gruntjs/grunt-contrib-less/blob/master/LICENSE-MIT

  18. Kristensen, Mads (2014-06-18). "WebEssentials2013/LICENSE.txt at master · madskristensen/WebEssentials2013". GitHub. Retrieved 2021-03-19. https://github.com/madskristensen/WebEssentials2013/blob/master/LICENSE.txt

  19. Bram van der Kroef (2017-07-11). "clessc/LICENSE at master · BramvdKroef/clessc". GitHub. Retrieved 2021-03-19. https://github.com/BramvdKroef/clessc/blob/master/LICENSE

  20. SamBrishes (2018-12-15). "snout.less/LICENSE.md at master · pytesNET/snout.less". GitHub. Retrieved 2021-03-19. https://github.com/pytesNET/snout.less/blob/master/LICENSE.md