How to Include CSS in Magento 2 for Custom Theme

cssjavascriptlayoutmagento2theme

I am trying to include custom css and js in custom theme and should come on all pages.

I have tried this from the Magento DevDocs, but I can't make it right and it's not showing. Please help me.

Best Answer

For keep css and js in all pages you have to customize default_head_blocks.xml file. set file,

magento2/app/design/frontend/{Vendor}/{themename}/Magento_Theme/layout/default_head_blocks.xml file

Put inside <head> tag,

<css src="css/styles.css"/> 
<script src="js/custom.js"/>

Add your css file inside,

app/design/frontend/{Vendor}/{theme}/web/css/styles.css

Add your custom js

 app/design/frontend/{Vendor}/{theme}/web/js/custom.js

Remove cache folder and try.

Its now working in all pages of site.

Related Topic