Magento2 – How to Add CSS Class on Body

magento2

I am trying to add a css class on body tag but not able to find any file, from where the body tag is rendered.

I need to add one css class on body tag such as others are coming >
page-with-filter page-products page-layout-2columns-left myclasshere

in previous version below was the xml code to add class on body.

<reference name="root">
    <action method="addBodyClass">
        <classname>my-profile</classname>
    </action>
</reference>

I tried using this but it didn't worked.

I need to add one class with page-layout-2columns-left template only.

Best Answer

In your layout or template file, you need to add an attribute to the body tag, like this:

<body>
    <attribute name="class" value="my-css-class"/>
    ...

Hope that Helps

Related Topic