Less (style sheet language) explained

Less
Designer:Alexis Sellier
Developer:Alexis Sellier, Dmitry Fadeyev
Programming Language:JavaScript
Typing:Dynamic
Influenced By:CSS, Sass
Influenced:Sass, Less Framework, Bootstrap (v3)
Operating System:Cross-platform
License:Apache License 2.0
File Ext:.less

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.[1] 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.[2] 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.[3]

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.

@pale-green-color: #4D926F;

  1. header

h2

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

  1. header

h2

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.

.rounded-corners (@radius: 5px 10px 8px 2px)

  1. header
  2. footer

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

  1. header
  2. footer

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

  1. header

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

  1. header h1
  2. header p
  3. header p a
  4. header p a:hover

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;

  1. header
  2. footer

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

  1. header
  2. footer

Comparison

Sass

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

Less is inspired by Sass.[5] 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.[6]

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

Name Description Software License Platform Functionality
WinLess - Windows GUI for less.js 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 Less Compiler Ms-PL[11] Visual Studio Plugin Compiler
Mindscape Web Workbench Syntax highlighting and IntelliSense for Less and Sass Proprietary Visual Studio Plugin Compiler
Syntax Highlighting
Eclipse Plugin for LessEclipse Plugin EPL 1.0[12] Eclipse Plugin Syntax highlighting
Content assist
Compiler
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 MIT[13] Node.js Compiler
Web Essentials Visual Studio extension with support for Less and Sass Apache 2.0 [14] Windows Syntax highlighting, Content assist, Compiler
clessc Pure C++ compiler MIT[15] at least Windows, Linux, MacOS Compiler
Less WebCompiler Web-based compiler MIT[16] at least Windows, Linux, MacOS Compiler, Syntax highlighting, Minifier

See also

Notes and References

  1. Web site: Getting started Less.js. The Core Less Team. 2021-03-19. Less.js.
  2. Web site: Sass and Less : Nex3. dead. https://web.archive.org/web/20090621074106/http://nex-3.com/posts/83-sass-and-less. Weizenbaum. Nathan. 2009-06-21. 2009-06-17. 2021-03-19.
  3. Web site: css - Is there a SASS.js? Something like LESS.js?. 2010-12-14. 2021-03-19. Meng. Jiew. Mortensen. Peter. Stack Overflow.
  4. Web site: What's Wrong With CSS. Atwood. Jeff. 2010-04-30. 2022-12-03. Coding Horror.
  5. Web site: About Less.js. The Core Less Team. 2021-03-19. Less.js.
  6. Web site: sass_and_less_compared.markdown. Eppstein. Chris. 2010-11-10. 2021-03-19. GitHub Gist.
  7. Web site: License Information · Issue #55 · marklagendijk/WinLess. Lagendijk. Mark. 2013-01-29. 2021-03-19. GitHub.
  8. Web site: Crunch/LICENSE.txt at master · matthew-dean/Crunch. Dean. Matthew. 2011-12-02. 2021-03-19. GitHub.
  9. Web site: less.js-windows/LICENSE at master · duncansmart/less.js-windows. Smart. Duncan. 2013-07-25. 2021-03-19. GitHub.
  10. Web site: SimpLESS/LICENSE.txt at master · Paratron/SimpLESS. Engel. Christian. 2012-07-29. 2021-03-19. GitHub.
  11. Web site: Chirpy - VS Add In For Handling Js, Css, DotLess, and T4 Files - CodePlex Archive. https://web.archive.org/web/20210220115440/https://archive.codeplex.com/?p=chirpy. 2021-02-20. Evan Nagle. 2021-03-19. CodePlex.
  12. Web site: Eclipse plugin for LESS. Vincent Simonet. 2021-03-19. normalesup.org.
  13. Web site: grunt-contrib-less/LICENSE-MIT at master · gruntjs/grunt-contrib-less. Kellen. Tyler. 2012-09-04. 2021-03-19. GitHub.
  14. Web site: WebEssentials2013/LICENSE.txt at master · madskristensen/WebEssentials2013. Kristensen. Mads. 2014-06-18. 2021-03-19. GitHub.
  15. Web site: clessc/LICENSE at master · BramvdKroef/clessc. Bram van der Kroef. 2017-07-11. 2021-03-19. GitHub.
  16. Web site: snout.less/LICENSE.md at master · pytesNET/snout.less. SamBrishes. 2018-12-15. 2021-03-19. GitHub.