Let's say I have my module which adds a slider to the homepage and there are many styles to define. I know I can add the styles in 2 different ways:

  • Adding a css file MyBrand/MyModule/view/frontend/web/css/myfile.css
  • Or adding a less file MyBrand/MyModule/view/frontend/web/css/source/_module.less

Is there a «more correct» way of adding my file? Should I priorize adding .css instead of .less, is there a specific good practice?

In the Magento docs I don't see any specific guideline regarding this.

Just a note: In my case I wanted to use the function .media-width, so I had to chosse using less.

2 Answers 2


Using css or less depends upon your requirement ,refer this for more information about this :- https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/css-topics/css-themes.html https://webkul.com/blog/use-less-magento-2/ https://zemez.io/magento/support/how-to/magento-2-quick-guide-create-custom-css-file/


you need to create the file view/frontend/layout/default.xml inside your custom module folder.

Default.xml is for supplement of JS, CSS or Less files on all pages

<?xml version="1.0"?>
<!-- /** * Copyright © 2015 Scommerce Mage. All rights reserved. * See COPYING.txt for license details. */ -->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <link src="MyBrand_MyModule::custom.js"/>
        <css src="MyBrand_MyModule::custom.css"/>

And very helpful this link refer this :-


Any query let me know..


  • Can you share your thoughts here - magento.stackexchange.com/questions/309714/… Commented Apr 7, 2020 at 5:29
  • Thank you for the approach. But it actually doesn't answer my question: should we prioritize including less over css files? Are there any guidelines? Harmendra's answer seems to be a little more explanatory :)
    – PauGNU
    Commented Apr 7, 2020 at 7:14
  • Please check attached link. Commented Apr 7, 2020 at 10:26

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.