AI Generate LESS docs instantly

LESS Cheat Sheet

Quick reference guide with copy-paste ready code snippets

Try DocuWriter Free

Getting Started

4 snippets

LESS basics and syntax

Comments

// Single line comment

/* Multi-line
   comment */

Import

@import "variables";
@import "mixins.less";

Nesting

.nav {
  background: blue;
  
  a {
    color: white;
    
    &:hover {
      color: yellow;
    }
  }
}

Parent Selector (&)

.button {
  &:hover { }
  &.active { }
  &-large { }  // BEM modifier
}

Variables

5 snippets

Storing and reusing values

Define Variables

@primary-color: #3498db;
@font-stack: Helvetica, sans-serif;
@base-spacing: 1rem;

Use Variables

.header {
  color: @primary-color;
  font-family: @font-stack;
  padding: @base-spacing;
}

Variable Interpolation

@name: "primary";

.alert-@{name} {
  color: red;
}

Property Name Interpolation

@property: color;

.widget {
  @{property}: blue;
  background-@{property}: red;
}

Lazy Loading

@var: 0;
.class {
  @var: 1;
  .nested {
    @var: 2;
    prop: @var;  // 2
  }
  prop: @var;  // 1
}

Mixins

5 snippets

Reusable style blocks

Simple Mixin

.border-radius(@radius: 5px) {
  -webkit-border-radius: @radius;
  -moz-border-radius: @radius;
  border-radius: @radius;
}

Use Mixin

.button {
  .border-radius(10px);
}

Parametric Mixin

.box-shadow(@x: 0, @y: 2px, @blur: 4px, @color: rgba(0,0,0,0.3)) {
  box-shadow: @x @y @blur @color;
}

Mixin Guards

.mixin (@a) when (@a > 10) {
  background-color: black;
}

.mixin (@a) when (@a <= 10) {
  background-color: white;
}

Mixin Pattern Matching

.mixin(dark; @color) {
  color: darken(@color, 10%);
}

.mixin(light; @color) {
  color: lighten(@color, 10%);
}

Tired of looking up syntax?

DocuWriter.ai generates documentation and explains code using AI.

Try Free

Functions

4 snippets

Built-in color and math functions

Color Functions

darken(@color, 10%);
lighten(@color, 10%);
saturate(@color, 20%);
desaturate(@color, 20%);
fadein(@color, 10%);
fadeout(@color, 10%);

Math Functions

ceil(2.1);      // 3
floor(2.9);     // 2
percentage(0.5); // 50%
round(1.67);    // 2
sqrt(25);       // 5

String Functions

e("\9");         // Escape
%("Rep %a", 1+2); // "Rep 3"
replace("Hi Tom", "Tom", "Bob");

Type Functions

isnumber(1234);     // true
isstring("str");    // true
iscolor(#fff);      // true
ispixel(10px);      // true

Operations

2 snippets

Math and string operations

Math Operations

@base: 5%;
@filler: @base * 2;    // 10%
@other: @base + @filler;  // 15%
width: 100% / 2;      // 50%

Color Operations

@color: #888 / 4;     // #222
@light: #888 + #111;  // #999
@dark: #888 - #111;   // #777

Namespaces & Scope

2 snippets

Organizing mixins and variables

Namespace

#bundle {
  .button {
    display: block;
    border: 1px solid black;
  }
}

.header a {
  #bundle.button();  // Use mixin
}

Scope

@var: red;

#page {
  @var: white;
  color: @var;  // white
  
  #header {
    color: @var;  // white
  }
}

Extend

2 snippets

Inheriting styles

Extend Selector

.a {
  color: red;
}

.b {
  &:extend(.a);
  background: blue;
}

Extend All

.a.b {
  color: red;
}

.test {
  &:extend(.a all);
}

Guards

4 snippets

Conditional logic

When Guard

.mixin (@a) when (@a >= 10) {
  background-color: black;
}

Multiple Conditions

.mixin (@a) when (@a > 10) and (@a < 20) {
  background-color: red;
}

OR Conditions

.mixin (@a) when (@a = 1), (@a = 2) {
  background-color: blue;
}

NOT Condition

.mixin (@a) when not (@a = 0) {
  background-color: green;
}

More Cheat Sheets

FAQ

Frequently asked questions

What is a LESS cheat sheet?

A LESS cheat sheet is a quick reference guide containing the most commonly used syntax, functions, and patterns in LESS. It helps developers quickly look up syntax without searching through documentation.

How do I learn LESS quickly?

Start with the basics: variables, control flow, and functions. Use this cheat sheet as a reference while practicing. For faster learning, try DocuWriter.ai to automatically explain code and generate documentation as you learn.

What are the most important LESS concepts?

Key LESS concepts include variables and data types, control flow (if/else, loops), functions, error handling, and working with data structures like arrays and objects/dictionaries.

How can I document my LESS code?

Use inline comments for complex logic, docstrings for functions and classes, and README files for projects. DocuWriter.ai can automatically generate professional documentation from your LESS code using AI.

Code Conversion Tools

Convert LESS to Other Languages

Easily translate your LESS code to other programming languages with our AI-powered converters

Related resources

Stop memorizing. Start shipping.

Generate LESS Docs with AI

DocuWriter.ai automatically generates comments, docstrings, and README files for your code.

Auto-generate comments
Create README files
Explain complex code
API documentation
Start Free - No Credit Card

Join 33,700+ developers saving hours every week