I have custom view.phtml. I Want add my.css and my.js in <head></head> 2 file in app\code\Test\New\view\frontend\web\css.

How do it?

  • was bellow answer useful ? Jan 5, 2016 at 7:16

1 Answer 1


You can add CSS file as following way for your custom module.

Open you layout file e.g. modulename_index_view.xml and following code in <head>

        <css src="Test_New::css/my.css"/>

to add custom module JS file you can use standard way as mentioned with below link.

How to load custom module js file in magento 2?

My suggestion (Optional)

You can use the standard way of Magento 2 to call css and js rather than Call CSS and JS files directly into layout file.

You can call JS using requirejs module. (You can maintain dependency of code.)

You may call css file using _module.less just put it under app\code\<Vendor>\<ModuleName>\view\frontend\web\css\source. So It will call automatically as well as _module.less will compile by grunt tool and converted into your theme or module css

Your Answer

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

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