Less (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.[2] 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.[3] 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.[2][4]

Less
Designed byAlexis Sellier
DeveloperAlexis Sellier, Dmitry Fadeyev
First appeared2009 (2009)
Stable release
3.9.0[1] / November 28, 2018 (2018-11-28)
Typing disciplineDynamic
Implementation languageJavaScript
OSCross-platform
LicenseApache License 2.0
Filename extensions.less
Websitelesscss.org
Influenced by
CSS, Sass
Influenced
Sass, Less Framework, Bootstrap (v3)

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

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

.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.[5]

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

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
WinLessGUI Less CompilerApache 2.0[8]WindowsCompiler
CrunchLess editor and compiler (requires Adobe AIR)GPL[9]Windows, Mac OS XCompiler
Editor
less.js-windowsSimple command-line utility for Windows that will compile *.less files to CSS using less.js.MIT License[10]WindowsCompiler
less.appLess CompilerProprietaryMac OS XCompiler
CodeKitLess CompilerProprietaryMac OS XCompiler
LessEngineLess CompilerFreeOpenCart PluginCompiler
SimpLESSLess Compilerfree but no explicit license[11]Windows
Mac OS X
Linux
Compiler
ChirpyLess CompilerMs-PL[12]Visual Studio PluginCompiler
Mindscape Web WorkbenchSyntax highlighting and IntelliSense for Less and SassProprietaryVisual Studio PluginCompiler
Syntax Highlighting
Eclipse Plugin for LessEclipse PluginEPL 1.0[13]Eclipse PluginSyntax highlighting
Content assist
Compiler
mod_lessApache2 module to compile Less on the flyOpen SourceLinuxCompiler
grunt-contrib-lessNode.js Grunt task to convert Less to CSSOpen SourceNode.jsCompiler
Web EssentialsVisual Studio extension with support for Less and SassApache 2.0WindowsSyntax highlighting, Content assist, Compiler
clesscPure C++ compilerGPLat least Windows, Linux, MacOSCompiler
Less WebCompilerWeb-based compilerMITat least Windows, Linux, MacOSCompiler, Syntax highlighting, Minifier

See also

References

  1. "CHANGELOG". GitHub.
  2. Official Less website Official Less website
  3. Sass and Less Archived 2009-06-21 at the Wayback Machine Sass and Less
  4. "css - Is there a SASS.js? Something like LESS.js?". Stack Overflow.
  5. What's Wrong With CSS What's Wrong With CSS
  6. About Less About
  7. Sass/Less Comparison
  8. WinLess github Issue "License Information"
  9. Crunch's LICENSE.txt at github Crunch's LICENSE.txt at github
  10. github license
  11. license file at github (placeholder)
  12. Chirpy License Information at CodePlex
  13. Eclipse Plugin for Less homepage Eclipse Plugin for Less homepage
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.