6

Is it possible to add individual CSS file on each cms page? Upon researching, I can do it by adding code on Layout update XML.

Unfortunately, it isn't working. Here's my code:

<head>
  <css src="Namespace_YourModule::css/styles.css"/>
</head>

enter image description here

3
  • Shall i know what is the scenario you need? Jul 4, 2017 at 13:20
  • i want to add css file on a specific cms page, in magento 1 here is the code <reference name="head"> <action method="addCss"> <stylesheet>css/custom.css</stylesheet> </action> </reference> i'm not sure on magento 2 Jul 4, 2017 at 13:23
  • Which magento 2 version you are using currently? Using custom module to set different css for different CMS page is working for me in magento 2.3.3 using Layout Update XML. Jan 12, 2020 at 13:09

2 Answers 2

0
<?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>
        <css src="css/mycustom.css" after="-" />
    </head>
</page>
0

If you're on < version 2.1.9 there was apparently a bug to prevent this from working, I've never tried it but you can read about it here - Adding CSS to a CMS page using Layout Update XML

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.