How to Add Custom CSS Class Through XML File in Magento 2

How to Add Custom CSS Class Through XML File in Magento 2

Magento 2 is widely popular among the developers’ community, owing to its insane capability to customize and tweak the default configuration and code.

With increasing online stores and various types of businesses built with Magento 2 as the platform, there ought to be crazy requirements to fulfill customers’ expectations.

Recently, I found myself in the exact same scenario where I was required to add custom CSS class through XML file in Magento 2.

As it is not recommended to completely change the layout of the XML, I preferred the below solution:

Method to add custom CSS class through XML file in Magento 2:

The below example is to add CSS class in the product page:

Override catalog_product_view.xml to your custom theme using the method here.

Add the below code:

Removing blocks and adding custom CSS/HTML classes are the usual requirements during store development. So, please bookmark this solution which is surely going to help you someday!

Also, if you have any doubts, just mention them in the Comments section below 🙂

I would be happy to help.

Feel free to share the solution with the Magento community via social media.

Thank You.

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

5
(based on 6 Reviews)

He is a senior Magento Developer at Meetanshi with an aim to serve the best to the store owners. In his free time, he loves to consume digital content with the family.

Leave a reply:

Your email address will not be published.