From Joomla! Documentation
Revision as of 16:02, 23 June 2013 by Wilsonge
- 1 Where can you find the .less stylesheets and compiler?
- 2 How to re-generate the CSS stylesheets
- 3 Compiling your own LESS files for your template
- 4 Not all LESS compilers are equal
- 5 Difference CSS vs LESS imports
- 6 From existing CSS to LESS / import CSS files
- 7 References
Where can you find the .less stylesheets and compiler?
.less building blocks are located in
media/jui/less/. The template specific
.lessfiles are located in
The CSS generation wrapper script, LESS compiler, and other similar build tools are located in the
build/ directory of the Joomla source located on GitHub. Refer to Git_for_Coders for more information on using GitHub. The build directory is only available from the Joomla source, it is not included in an official Joomla release.
How to re-generate the CSS stylesheets
To re-generate all the CSS files from a Joomla core distribution, you will need to execute the generation scripts as a CLI application.
cd joomla-cms/build c:\xampp\php\php.exe generatecss.php
Compiling your own LESS files for your template
To compile less files for your own template, you will need to take a copy of the
generatecss.php script and adjust it to suite your template.
Alternatively you can use a LESS Compiler plugin which compiles your .less files automatically on page reload: http://extensions.joomla.org/extensions/miscellaneous/development/22424
More alternatives and tools on a recent Joomla! Magazine article: http://magazine.joomla.org/issues/issue-may-2013/item/1289-tools-to-do-less
Not all LESS compilers are equal
The LESS compiler used for the Joomla core for code style consistency is obtained from leafo.net/lessphp.
If you're working on your own template you can use any compiler you like.
Difference CSS vs LESS imports
The main .less file and starting point e.g. in protostar is located in
If you open that file you will find many @imports in this file - imports from many different places. Unlike imports in CSS, imports in LESS get compiled to a single CSS file. This will result in fewer http requests and speed your site up.
From existing CSS to LESS / import CSS files
You may want to add your existing CSS files and classes to your LESS powered template or start with what you have. All CSS declarations are compatible with LESS so you can just rename your .css files to .less and you can compile and use them. You can then step by step make use of the great dynamic features LESS has to offer: variables, mixins, operations and functions. See http://www.lesscss.org
Notice: the examples below reference the default Protostar template for clarity. Your paths may be different. Notice: If you want to customize Protostar template it is a good idea to copy the template and customize it afterwards - so that Joomla! updates do not overwrite your customizations.
Option 1: import your .css as .less files
(a little bit work but worth it, imho)
Now lets assume you want to include your custom files and get them parsed by LESS compiler - you do NOT need to rewrite your .css to LESS because plain .css works as well. The only thing you have to do is to rename your .css files to .less and add an @import statement into above mentioned main /templates/protostar/less/template.less
I assume you put your custom .css files renamed to .less into the /templates/protostar/less folder. Now you open /templates/protostar/less/template.less and at the bottom of the file you import your custom .less files so that they override existing declarations:
@import "modules.less"; @import "components.less"; @import "articles.less";
If you now compile your main template.less file you end up with one main template.css optimized and minified (if you wish). You also reduced your http requests and the site should load faster. Now you can start step by step in your custom.less files to use less variables and other cool stuff http://lesscss.org has to offer.
Option 2: just import your .css / does not work for overriding
In /templates/protostar/less/template.less just import your .css files and they will be included as imports into main template.css:
@import "../css/modules.css"; @import "../css/components.css"; @import "../css/articles.css";
But this way you do not get any optimization. And a big issue is that this import is always on top before other declarations - so you can't override an existing declaration.
More information: http://lesscss.org/#usage (Section Importing)
http://jui.kyleledbetter.com/less - Example of building your own template.less