Magento 2: Add Local & External CSS and JS file

This article shows different ways to add CSS and JS files in Magento 2. Add CSS & JS from Layout XML file In this example, we are adding JS and CSS via layout file in your custom module. app/code/YourCompany/YourModule/ view/frontend/layout/frontName_controllerName_actionName.xml <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <head> <!– local CSS file –> <css src="YourCompany_YourModule::css/custom.css"/> <!– local … Read more