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

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

Implementation of WireMock for better testing

Spread the love WireMock is a flexible and powerful tool

Magento 2: How to selected default option in configurable options?

Spread the love Configurable products in Magento 2 allow

How To Implement Simple JWT Authentication in Django Rest Framework

Spread the love We’ll learn how to use simple JWT

Optimizing Search: Integrating Elasticsearch in Django Applications

Spread the love What is Elasticsearch? Elasticsearch is a

How to create Customer Segments

Spread the love In Magento 2, “customer

Proxy Design Pattern and Requisition List in Magento 2

Spread the love Requisition List in Magento 2 Requisition

bluethinkinc Blogs