In Magento 1 we can add inline CSS from admin Layout Update XML like this :

<reference name="head">
 <block type="core/text" name="custom_css">
  <action method="setText">
         <style  type="text/css">
            .my-class  {
                color: red;
         </style> ]]>

how can this be implemented in Magento 2 admin Layout Update XML?

I've tried it in Magento 2.2 but it did not work


2 Answers 2


This is not currently possible in Magento 2. You can add in CSS classes with XML (the example that @Christoph Farnleitner), but not actual CSS itself.

  • thanks.i just want to know whether the above mentioned method is applicable or not in magento 2.so, it is different way in magento 2 Jan 29, 2018 at 7:34
  • 1
    yeah. You might come across some xml in M2 that has "style" like attributes in them. These are the UI Component system and they have things like "width" and such are elements that can be defined. So at first it might look like you can, but this is just trickery on Magento's part that only works with that system. You can now load css on just the pages you want with xml, that is handy to reduce code on the site.
    – circlesix
    Jan 29, 2018 at 18:21

A little bit tricky, in the inside content field you can use like this :

<style xml="space"><!--
/* your css snippet here */
  • So you have to go through the Content section? If through the XML Update Layout, can it work too? Just curious. If can't, through Content it's more than enough. Thank you Bang Ansyori Apr 29, 2019 at 10:49

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.