What I don't understand is that since the .less files are already going to be compiled during development through Grunt, why does Magento 2 still uses oyejorge/less to compile less files through PHP?

Other than the themes, are there anywhere else in Magento that uses .less css files?

2 Answers 2


In short, it's a question of extendability. As you may know, you are able to use .less files inside of custom modules. Let's imagine a situation when a store using some custom theme and in your extension you want to make a color of some elements the same as heading color of current theme like:

section h1: {
    color: @heading-color

In this case, your extension can use the heading color without knowing the exact color. If you have a precompiled CSS in your extension out of the box, you will have this color hard-coded or you will have to use a standard theme's set of CSS classes instead. So, using PHP LESS compilation Magento 2 allows 3rd party extension to be integrated into custom themes in more handy and flexible way.

  • I see. Do people really have a lot of HTML/LESS (CSS) in their modules? I'm thinking this is going to make maintaining the frontend difficult because different parts of your frontend will be all over the place segregated over the different extensions or modules? I'm fairly new to Magento2 and I might be missing something here.
    – xenon
    Oct 20, 2016 at 16:42
  • @xenon It won't really be segregated, it's rather the opposite, the possibility of using variables for common values reduces redundancy and makes the code more easily maintainable. And it basically also means your module will match the store's look out of the box without any additional work necessary on the shop owner's end.
    – TiEul
    Oct 20, 2016 at 18:53
  • But we are not living in Utopia and most of extensions have crappy front-end. But if you have some good examples, I'll be glad to check them.
    – igloczek
    Oct 20, 2016 at 22:39

In developer mode, LESS compilation happens on the fly when a resource that is not compiled yet is requested. This only works with PHP.

Also Magento adds its own features to LESS: //@magentoImport, which respects theme fallback and is preprocessed with PHP, before the actual LESS compilation takes place. So there is no way around using PHP anyways. The Magento 2 Grunt task actually triggers PHP compilation via bin/magento.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.