how can i add custom.less file for any specific page in child theme? means don't need genrate inside my custom css code in style-l.css or style-m.css and i have already 2 methods used.

Method 1.

create _custom.less and add css code


_source.less (import in _cutom.less)



Method 2.

create "_custom.less" and "_extend.less" on same location


import _custom.less in _extend.less


both of methods generate in style-l.css or style-m.css. but i want generate on browser css with specific css link.

2 Answers 2


You can do something like this, for example:


<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <css src="Vendor_Custom::css/custom.css" />


   #maincontent {
        padding: 0;
  • dear @Reshad, thanks for reply. i have use this method but grunt not compile on same time. when i remove pub/static folder and run static:content:deploy: command then generate css. i want when i save .less file generate css file on same time.
    – Gaurav
    Commented Jan 6, 2023 at 6:19

You can make your changes in your theme Less file then they will merge automatically into styles-m.css and styles-l.css

If you are generating browser CSS like custom.css so you can create a custom.css file at app/design/frontend/Vendor/theme/web/css/

Or you can not create CSS files only use Less file for the specific page you can create _module.less file for the specific module for your requirement.

For example, create module.less at Vendor_Module/web/css/source/ path and put your style into this less file.

And if you want to view your created file on the browser then according to the custom.css module.less than use grunt and refer to the below link

Compile LESS with Grunt

  • ok thanks for your reply. i will check & let you know.
    – Gaurav
    Commented Oct 31, 2022 at 6:12

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.