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">

I tried using this but it didn't worked.

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


1 Answer 1


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

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

Hope that Helps

  • Thanks Dave, now it is appearing on all pages, I just want this class which have layout of page-layout-2columns-left
    – Jack
    Commented Mar 2, 2016 at 6:30
  • Can't think of a way you'd easily achieve that with layout alone, other than targeting each page handle that uses 2column-left as a layout, much the same as M1. Commented Mar 2, 2016 at 7:18
  • 1
    I was just thinking to add the same lines in 2-columns-left.xml so this will target only this layout but its not working.
    – Jack
    Commented Mar 2, 2016 at 8:14
  • I just added the same on category.xml and it worked, thanks :)
    – Jack
    Commented Mar 2, 2016 at 10:59
  • how to add only for login user? Commented Jun 8, 2016 at 7:04

Your Answer

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

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