How to use less file in asp net core


ASP.NET is a popular programming language used for building web applications. In this article, we will explore how to use a less file in ASP.NET Core.

What is Less?

Less is a CSS preprocessor that extends the of CSS. It allows you to use variables, mixins, functions, and that are not available in CSS. Less files have a .less extension and need to be compiled into CSS before they can be used in a web application.

Setting up Less in ASP.NET Core

To use Less in ASP.NET Core, you need to install the Less compiler and configure it in your project. Here are the :

Step 1: Install the Less compiler

Open the Package Console in Visual and run the following command to install the Less compiler:

Install-Package dotless

Step 2: Configure Less in your project

In your ASP.NET Core project, open the .cs file and add the following code to the ConfigureServices method:

services.AddMvc().AddRazorPagesOptions(options =>
    options.Conventions.AddPageRoute("/Home/Index", "");

This code configures the Less compiler to automatically compile Less files into CSS when they are requested by the browser.

Using a Less file in ASP.NET Core

Once you have set up Less in your ASP.NET Core project, you can start using Less files in your web application. Here's an example:

    ViewData["Title"] = "Home";

Welcome to my website

This is a paragraph using Less.


Using Less in ASP.NET Core allows you to take advantage of advanced CSS features and improve the maintainability of your web application's styles. By following the steps outlined in this article, you can easily integrate Less into your ASP.NET Core project and start using Less files in your web application.

Rate this post

Leave a Reply

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

Table of Contents