Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
Less.js @import At-Rules
Next article icon

Less.js @import At-Rules Reference

Last Updated : 13 Nov, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. With the help of this dynamic style sheet language, CSS is more functional. LESS offers cross-browser compatibility. CSS is improved and compiled using a computer language called the CSS pre-processor so that web browsers may use it. It is also a CSS language extension that provides features like variables, functions, mixins, and operations that help us develop dynamic CSS while retaining backward compatibility.

In this article we are going to see the Less.js@import At-Rules reference is used to import external files but the imported code is not added to the compiled CSS file. This provides two options to us which are extend and mixins, and the result may vary depending upon which option is being chosen. When the selector is extended, only the new selector has this designation, and it is inserted after the reference @import declaration. A reference style's rules are mixed-in, tagged "not reference," and appear in the preferred location as usual when it is used as an implicit mixin.

Syntax:

@import (reference) "value";
 

Parameters:

  • value: This is the compulsory parameter for @import (reference), this generally contains a file path or a filename that directs to the main file.

Example 1: The code below demonstrates the usage and implementation of the  @import (reference). Here we have used the extend then the extended part is just imported to the CSS code.

index.html
<!DOCTYPE html> <html>  <head>     <link rel="stylesheet" type="text/css"           href="style.css" /> </head>  <body>     <h1 style="color:green">GeeksforGeeks</h1>     <h3><b>Less.js @import At-Rules optional</b></h3>     <div class="container">     </div>     <br>     <p class="text">Box1</p>     <p id="test">Box2</p> </body>  </html> 
styles.less
@import (reference) "test.less";     .container:extend(.container all){  } 
test.less
@body-bg-color: #eeeeee; @text-color: rgb(0, 200, 100); @container-bg: rgb(220, 43, 55);  body {     background: @body-bg-color; }  .container {     height: 100px;     width: 100px;     padding: 30px 0px 0px 25px;     background-color: (#cc3eff);     color: yellow; }  .text, #test {     color: brown;     font-size: 2rem; } 


Now, to compile the above LESS code to CSS code, run the following command:

lessc styles.less styles.css

The compiled CSS file comes to be: 

style.css
.container {     height: 100px;     width: 100px;     padding: 30px 0px 0px 25px;     background-color: #cc3eff;     color: yellow; } 

Output:

 

Example 2: The code below demonstrates the usage and implementation of the  @import (reference). Here we have used implicit mixins and the code of the mixin is just imported to the CSS code.

index.html
<!DOCTYPE html> <html>  <head>     <link rel="stylesheet" type="text/css" href="style.css"/> </head>  <body>     <h1 style="color:green">GeeksforGeeks</h1>      <h3><b>Less.js @import At-Rules Reference</b></h3>     <div class="container">     </div>     <br>     <p class="mixed-in">Box1</p>     <p class="mix-in">Box2</p> </body>  </html> 
styles.less
@import (reference) "test.less"; .mix-in{     .text(); } .mixed-in{     #test(); } 
test.less
@body-bg-color: #eeeeee; @text-color: rgb(0, 200, 100); @container-bg: rgb(220, 43, 55);  body {     background: @body-bg-color; }  .container {     height: 100px;     width: 100px;     padding: 30px 0px 0px 25px;     background-color: (#cc3eff);     color: yellow; }  .text, #test {     color: brown;     font-size: 2rem; } 

Now, to compile the above LESS code to CSS code, run the following command:

lessc styles.less styles.css

The compiled CSS file comes to be: 

style.css
.mix-in {     color: brown;     font-size: 2rem; } .mixed-in {     color: brown;     font-size: 2rem; } 

Output:

 

Reference: https://lesscss.org/features/#import-atrules-feature-reference 


Next Article
Less.js @import At-Rules

P

priyanshuchatterjee01
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • LESS
  • Less.js-Functions

Similar Reads

  • Less.js @import At-Rules once
    Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. This dynamic style sheet language gives CSS more functionality. LESS provides interoperability across browsers. A programming language called CSS pre-processor is
    3 min read
  • Less.js @import At-Rules less
    In this article, we will see that Less.js @import At-Rules is basically used to import the file which is in the source code. And we can put the @import statement anywhere in the source code. And @import At-Rules allow us to spread the less code over to different files. Using the @import keyword we c
    2 min read
  • Less.js @import At-Rules
    Less.js @import At-Rules is basically used to import the file which is in the source code. And we can put the @import statement anywhere in the source code. And @import At-Rules allow us to spread the less code over to different files. Using the @import keyword we can separate and maintain our code
    3 min read
  • Less.js @import At-Rules optional
    Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. This dynamic style sheet language expands the capabilities of CSS. LESS provides cross-browser compatibility. Using a computer language called CSS pre-processor, C
    2 min read
  • Less.js @import At-Rules css
    Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. It is a dynamic style sheet language that makes CSS more powerful. LESS provides cross-browser compatibility. A programming language called CSS pre-processor is us
    3 min read
  • Less.js @import At-Rules multiple
    Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. It is a dynamic style sheet language that boosts the functionality of CSS. Cross-browser interoperability is offered via LESS. CSS is improved and compiled for usa
    3 min read
  • Less.js @import At-Rules Inline
    Less.js (Leaner Style Sheets) is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. It is a dynamic style sheet language that enhances the working power of CSS. LESS supports cross-browser compatibility. CSS pre-processor is
    3 min read
  • Less.js @import At-Rules Import Options
    LESS is a Leaner Style Sheets, a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. It is a dynamic style sheet language that enhances the working power of CSS. LESS supports cross-browser compatibility. CSS pre-processor is a
    3 min read
  • Less.js @import At-Rules File Extensions
    Less.js (Leaner Style Sheets) is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. It is a dynamic style sheet language that enhances the working power of CSS. LESS supports cross-browser compatibility. CSS pre-processor is
    4 min read
  • Less.js @plugin At-Rules
    In this article, we will understand the concepts related to Less.js @plugin At-Rules with different illustrations and examples. Less.js @plugin At-Rules is used to import the JavaScript plugin to add additional functions and features. Basically using the @plugin at rule is similar to an @import for
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences