Magento 2 – How to Add CSS Class on HTML

magento2

I would like to add "nav-before-open nav-open" in html tag by default in Magento2. if any one have idea ?

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

I have added class in body tag using below code

<body>
    <attribute name="class" value="demo"/>
</body>

Best Answer

Magento adding that class for body using below class Magento\Framework\View\Result\Page.php

  protected function render(HttpResponseInterface $response)
    {
..............
........
 'htmlAttributes' => $this->pageConfigRenderer->renderElementAttributes($config::ELEMENT_TYPE_HTML),
................

It is work same like you are adding for body

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<html>
        <attribute name="class" value="page-with-filter"/> 
    </html>
</page>

Output: http://easycaptures.com/3327274226