Less (Leaner Style Sheets; sometimes stylized as LESS) is a dynamic
preprocessor
In computer science, a preprocessor (or precompiler) is a Computer program, program that processes its input data to produce output that is used as input in another program. The output is said to be a preprocessed form of the input data, which i ...
style sheet language
A style sheet language, or style language, is a computer language that expresses the presentation of structured documents. One attractive feature of structured documents is that the content can be reused in many contexts and presented in various ...
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
Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use and view the source code, design documents, or content of the product. The open source model is a decentrali ...
project. Its first version was written in
Ruby
Ruby is a pinkish-red-to-blood-red-colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapph ...
; however, in the later versions, use of Ruby has been
deprecated
Deprecation is the discouragement of use of something human-made, such as a term, feature, design, or practice. Typically something is deprecated because it is claimed to be inferior compared to other options available.
Something may be deprec ...
and replaced by
JavaScript
JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior.
Web browsers have ...
. The indented syntax of Less is a
nested metalanguage, as valid CSS is valid Less code with the same
semantics
Semantics is the study of linguistic Meaning (philosophy), meaning. It examines what meaning is, how words get their meaning, and how the meaning of a complex expression depends on its parts. Part of this process involves the distinction betwee ...
. Less provides the following mechanisms:
variables,
nesting,
mixin
In object-oriented programming languages, a mixin (or mix-in) is a class that contains methods for use by other classes without having to be the parent class of those other classes. How those other classes gain access to the mixin's methods depe ...
s,
operators
Operator may refer to:
Mathematics
* A symbol indicating a mathematical operation
* Logical operator or logical connective in mathematical logic
* Operator (mathematics), mapping that acts on elements of a space to produce elements of another ...
and
functions; the main difference between Less and other CSS precompilers is that Less allows real-time compilation via less.js by the browser.
Features
Variables
Less allows variables to be defined. Variables in Less are defined with an
at sign
The at sign () is an accounting and invoice abbreviation meaning "at a rate of" (e.g. 7 Widget (economics), widgets @ £2 per widget = £14), now seen more widely in email addresses and social media platform User (computing), handles. It is norm ...
(@). 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;
#header
h2
The code above in Less would compile to the following CSS code.
#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)
#header
#footer
The above code in Less would compile to the following CSS code:
#header
#footer
Less has a special type of ruleset called parametric mixins which can be mixed in like classes, but accepts parameters.
#header
The above code in Less would compile to the following CSS code:
#header h1
#header p
#header p a
#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;
#header
#footer
The above code in Less would compile to the following CSS code:
#header
#footer
Comparison
Sass
Both
Sass and Less are CSS preprocessors, which allow writing clean CSS in a programming construct instead of static rules.
Less is inspired by Sass.
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.
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
JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior.
Web browsers have ...
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
See also
*
Sass (style sheet language)
Sass (short for ''syntactically awesome style sheets'') is a preprocessor scripting language that is interpreted or compiled into Cascading Style Sheets (CSS). SassScript is the scripting language itself.
Sass consists of two syntaxes. The ...
*
Stylus (style sheet language)
References
External links
*
{{Stylesheet languages
2009 software
Free computer libraries
JavaScript libraries
Software using the Apache license
Stylesheet languages