How to add custom less file in Magento2

Blog
Spread the love

Source files *.css included into layout files are compiled from *.less files. For example, let’s check any layout file of blank theme, the following .css files are inclued in the head:

The root source files for the Blank theme:

Magento_Blank_theme_dir/web/css/styles-m.less

Magento_Blank_theme_dir/web/css/styles-l.less

Magento_Blank_theme_dir/web/css/print.less

So, to add our custom.less file, we have to include custom.css, which is the compiled from .less file, in the layout file as shown below:

And create custom.less file on path /web/css/custom.css:

Now run below commands:

– Remove existing page cache and view preprocessed to apply less

rm -rf var/cache/* var/page_cache/* generated/code/* generated/metadata/* var/view_preprocessed/* pub/static/frontend/*

– Deploy static content php bin/magento setup:static-content:deploy -f

– Flush the cache by running php bin/magento cache:flush

The source “css/custom.css” file is compiled from “css/custom.less” file.

Read More About Less Compilation Mode:

https://developer.adobe.com/commerce/frontend-core/guide/css/preprocess/#less-compilation-modes

Vikas Mishra

Vikas Mishra

2024-09-05

0

Leave a Reply

Your email address will not be published. Required fields are marked *

Find More Blogs

Customize lead qualification for a seamless experience

Spread the love When the 2024 Release Wave 2 was launched,

Create a Custom Console Command in Spryker

Spread the love In Spryker, developers can create custom

SALESFORCE

Spread the love Salesforce is a cloud-based software

CRUD Operation in Spryker Backoffice with a Custom Module

Spread the love Spryker is a highly flexible and modular

How to create custom module on Spryker for Backoffice?

Spread the love Creating a custom module in Spryker

How to Install Spryker Project with Docker on Local Machine

Spread the love Spryker is a flexible and scalable commerce

How to Add a Custom Tab to the Customer Order Detail Page in Magento 2

Spread the love Adding a custom tab to the Order Detail

Exception Handling in Java

Spread the love Introduction – Exception:An unwanted

How to add custom less file in Magento2

Spread the love Source files *.css included into layout

Spring Boot Microservices

Spread the love Microservices architecture has become

bluethinkinc Blogs