cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 add class to body via Layout Update XML

Magento 2 add class to body via Layout Update XML

How I can add class to a body tag for CMS page via Layout Update XML. I am trying different variants like this

 

<referenceContainer name="root">
  <attribute name="class" value="my-css-class"/>
</referenceContainer>

But nothing works.

1 REPLY 1

Re: Magento 2 add class to body via Layout Update XML

@x_falkone_x

 

Have you tried using htmlClass="new-class" ? 

<referenceContainer name="my.container" htmlClass="new-class" />

For further details: https://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/xml-manage.html 

 

Please accept my answer as Solution if I was able to help. 

 

Magento Certified Solution Specialist | Lead Magento developer
If this response was helpful to you, consider giving kudos to this post