I have created New page_layout empty.xml. I need to remove some JS and CSS from this layout. I already try <remove src="print.css"/> But it gives an error Exception #0 (Magento\Framework\Config\Dom\ValidationException): Element 'remove', attribute 'src': The attribute 'src' is not allowed.


<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <update handle="empty"/>
    <referenceContainer name="head" remove="true"/>
    <referenceContainer name="header" remove="true"/>
    <referenceContainer name="menu" remove="true"/>
    <referenceContainer name="notifications" remove="true"/>
    <referenceContainer name="footer" remove="true"/>
    <referenceContainer name="body" remove="true"/>
    <remove src="print.css"/>

1 Answer 1


Here is the best example to remove js or css using layout xml files.

    <!-- Remove local styles resources -->
    <remove src="css/styles-m.css" />
    <remove src="<Namespace>_<ModuleName>::css/styles.css" />

    <!-- Remove js resources -->
    <remove src="my-js.js" />
    <remove src="Magento_Catalog::js/sample1.js" />

    <!-- Remove external resources -->
    <remove src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css" />
    <remove src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" />
    <remove src="http://fonts.googleapis.com/css?family=Montserrat" />

For more information, you can see here, Remove static links using layout

Please check like this and if this help you then hit like.

Thank you,

Hiren Patel

  • Your code will work for the layout file But I need the solution for the page_layout file. Commented Oct 5, 2020 at 5:39

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.