Adding attribute or class to the body tag in Magento 2

0
88
add custom class and attribute to body tag

In this tutorial we will explain how you can add your own class to the body tag and also I’ll add an attribute with its value in Magento 2.

See below for a more detailed example.

<?xml version=”1.0″?>
<page xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:View/Layout/etc/page_configuration.xsd”>
<body>
             <attribute name=”class” value=”custom-class”/>
              <attribute name=”data-var” value=”some-data”/>
</body>
</page>

Now clear the cache and check for the result.

The attribute tag is use add attributes to the body.

add class to body magento2