Request Quote

How to add attribute to the body tag in Magento 2

Here I will explain how to add attributes to the body tag. Magento 2 by default adds the controller name and the page layout name as class to the body tag. In this blog I will explain how you can add your own class to the body tag and also I’ll add an attribute with its value.

In the layout file add the following,

<?xml version="1.0"?>
<page xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <attribute name="class" value="custom-class"/>
        <attribute name="data-var" value="some-data"/>

The attribute tag is use add attributes to the body.


. . .


Add Your Comment

Be the first to comment.

Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again