How do you add a class to a pre existing xml block?


<container name="alert.urls" as="alert_urls" label="Alert Urls" after="product.price.tier"/>
            <block class="Magento\Catalog\Block\Product\View" name="product.info" template="product/view/form.phtml" after="alert.urls">
  • This question is unclear as to wether you are asking about adding a htmlClass to a block or container please clarify, as the responses assume block, if so you should edit the title to use the word "block" instead of container
    – Joel Davey
    Oct 6 '18 at 18:52

Recently I've had the need for the exact same function. I decided to look at the core XML files, and found the following code to work:

<referenceBlock name="product.info" htmlClass="yourClassName canUseMutipleNames" />

I found the above code in the core file at this location:


You can use this file as a reference and find some other useful tags like htmlTag :)


I have found some code in Magento XML core file

Please Try this code:

container name = "container_name" label="form" htmlTag="div" htmlClass="old-class" after='-'


Since Magento 2.3.2 you need to use arguments to referenceBlock/referenceContainer, for container/block use htmlClass

    <argument name="css_class" xsi:type="string">header links</argument> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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