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

Custom API to Fetch Customer Data by Customer ID in Spryker

Spread the love Introduction In this blog post, we will

Creating a Custom Module for a Custom Frontend Page in Spryker

Spread the love To create a custom module for a custom

How to create custom module api get category list without access token in Spryker

Spread the love To create a custom API for fetching a

Creating a Custom Glue API in Spryker

Spread the love Spryker’s Glue API is a powerful tool

Get AI Generated 360-Degree View of Account Summary in Dynamics 365 Sales

Spread the love Navigating the demanding landscape of sales

Enhancing Productivity with Dynamics 365: The Power of Session Restore

Spread the love Enhancing Productivity with Dynamics 365:

Salesforce Admin

Spread the love In our last blog, we discussed common

Unlocking AI with Spring Boot: Real-World Use Cases and Solutions

Spread the love Artificial Intelligence (AI) has moved from

Enhancing Performance with Reactive Java: A Beginner-Friendly Guide

Spread the love In today’s fast-paced software

Integrating Azure Function with Dynamics 365

Spread the love Signup on azure portal and make sure to

bluethinkinc Blogs