I added div(container) in every page except homepage like this

        <div class="myclass">
              all content here

I tried update layout from admin and cms_index_index.xml file by using remove tag but doesn't work for me. I only need to remove that container class or div not all child blocks & containers

Let's consider my container in my empty.xml (override).

<container name="container_name" htmlClass="myclass" htmlTag="div"/>

It's come as I want but I don't want it on homepage

How can I remove that container from homepage.

  • I hope my answer will resolve your issue. Jun 12, 2018 at 13:29
  • @NikunjVadariya any alternative solution for add div using container in all pages except homepage ? Jun 12, 2018 at 13:33
  • first you need to add it for all page and then remove it for the home page as i describe in my updated answer. it is the sort and good way to solve your issue thanks. Jun 12, 2018 at 13:36

3 Answers 3


You can remove class by this way:

Go to your admin panel > cms home page. There is one tab DESIGN and in this tab add your XML code in Layout Update XML area.

<referenceContainer name="container_name" htmlClass="">

Keep empty so it will remove the class.

Run command:

php bin/magento cache:flush


You can do it using two ways:

using xml file and add code in admin let me describe both solution.

solution 1: Create XML file

Create cms_index_index.xml file

add code

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <referenceContainer name="container_name" remove="true"/>

Solution 2: add same code from admin side

Go to your admin panel > open cms home page. There is a one tab DESIGN and in this tab add your xml code in Layout Update XML area. enter image description here

Both are working as per your requirement.(y)

  • sorry I forgot to mention what I tried I already tried this . I need to remove my that div /class not all container . it remove all containter child containers and blocks also Jun 12, 2018 at 13:22
  • @lalitmohan It will be like <referenceContainer name="main.content" htmlClass="new-class-name"/> Aug 25, 2021 at 11:18

If you want to declare block for magento theme.

Place block declaration into the



for magento module

place block declaration into the



<?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">
  <referenceContainer name="page.top"> 
        <container name="banner" as="banner" label="Banner"   htmlTag="div" htmlClass="banner" htmlId="banner">
            <block class="Magestore\Bannerslider\Block\Bannerslider" name="bannerslider.content.top" before="-" />

You can refer this blog for better understanding.

  • I already have that cms_index_index.xml I know very well. I need to remove only class not child containers & blocks within that container Jun 12, 2018 at 13:23

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.