🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How To Add CSS & Javascript Files To CMS Pages In Magento 2

By Sanjay JethvaUpdated on May 22, 2025 1 min read

Magento 2 is a flexible E-commerce platform with the potential to customize the features for a feasible performance. One of the examples to do so is to add CSS & Javascript files to CMS pages in Magento 2.

Adding CSS & Javascript files to Magento 2 CMS pages allows optimizing the speed performance. For example, you want to implement a feature on a single CMS page, you can do so using the below code.

It is recommended to add the relevant JS and CSS files to the specific CMS pages only. For example, you want to implement a popup on one page and add slider on any other page, say, homepage, etc.

Such particular features to be implemented on not all but specific pages require applying custom CSS and Javascript files to Magento 2 CMS pages.

And here’s the easy method to do so:

Steps to add CSS & Javascript files to CMS pages in Magento 2:

Add the following code to Admin > Content > Elements > Pages > CMS Page > Design > Layout Update XML

<head>
<css src="Vendor_Extension::css/custom.css"/>
<script src="Vendor_Extension::js/custom.js"/>
</head>

That’s it.

Also, I’d be grateful if you can help spread the solution among the Magento community via social media.

Thank you.

Also Read:

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.