Back to Top

How to remove JS and CSS in Magento 2 using layout XML

Updated 8 April 2024

Sometimes, there is a need to remove some static resources(CSS and JS) from a page as there may be conflicts between the theme and the module(extensions) static resources(CSS and JS).

The <remove> tag is used in layout XML under the <head> tag to remove the static resources(CSS and JS files) linked to a page.

Note, that if a static asset is added with a module path (for example Vendor_Module::js/name.js) in the initial layout, you need to specify the module path when removing the asset.

<page xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <remove src="name.css"/>
      <remove src="css/name.css"/>
      <remove src="js/name.js"/>
      <remove src="Vendor_Module::js/name.js"/>

If you want to remove static resources(CSS and JS files) on all pages then you need to create a default.xml, the code will be as above only.

For more reference please visit the following link – Layout customizations

Searching for an experienced
Magento 2 Company ?
Find out More
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


  • luenib
    • Sagar Bathla (Moderator)
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home