How to connect a css to an xml in magento

The reason why <css src="css/list.css" rel="stylesheet" type="text/css" /> did not work is that it is not a valid syntax in Magento 2 XML layout files.

In Magento 2, the <css> tag is a custom XML tag specifically designed to include CSS files within the context of the Magento framework. It handles various functionalities, such as merging and minification of CSS files, and ensures proper integration with the system.

On the other hand, <link href="css/list.css" rel="stylesheet" type="text/css" /> is the standard HTML way of linking an external CSS file. It is used in HTML templates or static HTML files but not in Magento 2 XML layout files.

To ensure proper functionality and compatibility with Magento 2, it’s recommended to use the <css> tag with the correct syntax, such as <css src="Magento_Catalog::css/list.css"/>, in XML layout files when including CSS files.

Using the correct syntax ensures that Magento can handle the CSS file appropriately and apply any necessary optimizations or customizations defined in the system configuration.

Leave a comment

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