New: lessphp 0.4.0, compiles Bootstrap 3, breaking changes, see Changelog (August 9th 2013)


lessphp is a compiler for LESS written in PHP.

The entire compiler comes in a single includable class, but an additional command line interface to the compiler is included. It will run on PHP 5.1+. See the quick start for basic usage.

For an overview of the syntax take a look at the lessphp documentation.

Follow the author on twitter for updates: @moonscript.


Use the live demo to test the compiler using your own code, or click through the example buttons to see various parts of the language.

Edit me ↴

CSS comes here, click compile to build.
· Go to fullscreen version


stable: lessphp-0.4.0.tar.gz

source: http://github.com/leafo/lessphp

lessify: http://leafo.net/lessphp/lessify/


If you use Packagist for installing packages, then you can update your composer.json like so:

  "require": {
    "leafo/lessphp": "0.4.0"

Quick Start

The typical flow of lessphp is to create a new instance of lessc, configure it how you like, then tell it to compile something using one built in compile methods.

The compile method compiles a string of LESS code to CSS.

require "lessc.inc.php";

$less = new lessc;
echo $less->compile(".block { padding: 3 + 4px }");

The compileFile method reads and compiles a file. It will either return the result or write it to the path specified by an optional second argument.

echo $less->compileFile("input.less");

The compileChecked method is like compileFile, but it only compiles if the output file doesn’t exist or it’s older than the input file:

$less->checkedCompile("input.less", "output.css");

If there any problem compiling your code, an exception is thrown with a helpful message:

try {
  $less->compile("invalid LESS } {");
} catch (exception $e) {
  echo "fatal error: " . $e->getMessage();

The lessc object can be configured through an assortment of instance methods. Some possible configuration options include changing the output format, setting variables from PHP, and controlling the preservation of comments, writing custom functions and much more. It’s all described in the documentation.


A complete reference manual can be found on the documentation page.

A list of changes is available on the changelog page.


Various lessphp plugins exist for many frameworks:

If you've got one, email me it and I'll post it here.


If you find something that isn’t working right feel free to leave a comment or post on the GitHub issues tracker. If you have any interesting ideas for additions to the language please do suggest them as well. You can also email me if you want.


If you have a GitHub account, you can post bug reports on the github issues tracker.

generated by sitegen on Wed Jan 8 11:03:18 2014 · created by leaf corcoran · lessphp is licensed under GPL3/MIT