SlideShare a Scribd company logo
START USING LESS CSS
By: Ali MasudianPour <masud.amp@gmail.com>

LESS CSS - A BASIC INTRODUCTION

1
WHAT IS LESS CSS
•

Dynamic CSS
• Less is a “dynamic stylesheet language”

•

LESS extends CSS with dynamic behavior such as variables, mixins, operations and
functions.

•

LESS runs on both the server-side (with Node.js and Rhino) or client-side (modern
browsers only)

LESS CSS - A BASIC INTRODUCTION

2
COMPILING IN BROWSER
•

Less.js will perform AJAX requests to grab your Less files, will then process those files to
convert them into CSS, and finally inject the resulting CSS in the head of your document.

•

There is a bad thing about it
•

if the user‟s JavaScript is deactivated, it will not work!

LESS CSS - A BASIC INTRODUCTION

3
LET‟S START
•

LESS codes are written into a file with .less extension

•

Variables

• Less variables can be declared and used with the @ symbol.
• Example:
@white: #fff;

.class{
background-color:@white;
}

LESS CSS - A BASIC INTRODUCTION

4
LET‟S START
•

In addition, we can assign a variable to another
•

For instance:
•

•

@myDefaultColor:@white;

MIXINS
•

With Less we can define “mixins”, which are something comparable to functions in other programming languages. In Less they‟re used
to group CSS instructions.
.Round{
-webkit-border-radius:9999px;
-moz-border-radius:9999px;
border-radius:9999px;
}
#shape1{
.Round;
}
That‟s really simple!

LESS CSS - A BASIC INTRODUCTION

5
PARAMETRIC MIXINS
•

In LESS we can define parametric mixins. So we can send parameters through mixins
•

Example:
@defaultRadius:30px;
.RoundedShape(@radius:@defaultRadius){
-webkit-border-radius:@radius;
-moz-border-radius:@radius;

border-radius:@radius;
}
•

What an incredible feature!

LESS CSS - A BASIC INTRODUCTION

6
PARAMETRIC MIXINS
.Round{
.RoundedShape(9999px);

}
.RoundedSquare(@radius:@defaultRadius){

.RoundedShape(@radius);
}

LESS CSS - A BASIC INTRODUCTION

7
OPERATIONS
•

One other powerful feature of Less is the ability to use mathematical operations in your
stylesheets.

•

You can add, subtract, multiply and divide values

•

Example
@defaultShapesWidth:200px;
@borderSize:@defaultShapesWidth * 0.1;

•

it also works for colors
@defaultThemeColor:@lightBlue;
@borderColor:@defaultThemeColor - #222;

LESS CSS - A BASIC INTRODUCTION

8
COLOR FUNCTIONS
•

Less provides the following color functions:
•

darken() and lighten(), which add some black or white

•

saturate() and desaturate(), to make a color more colorful or more grayscale

•

Fadein() and fadeout, to increase or reduce transparency

•

Spin(), which modifies the hue of the color
• Examples:
@borderColor: desaturate(@defaultColor,100%)
@borderColor: darken(desaturate($defaultColort,100%),20%)
@defaultColor:spin(@mycolor1,100)

LESS CSS - A BASIC INTRODUCTION

9
NESTED RULES
•

When designing a complex page using css, you often have to chain selectors to aim a particular element in the DOM, like
this:
#header h1{}
#main h1{}
•

With LESS you can nest rules inside parent rules to mimic the DOM structure:
#header {
h1{}
}

.shape{
}
•

&:hover{background-color:@myColor;}
This & symbol represents the current selected elements. It is the equivalent of “THIS” in most programming language

LESS CSS - A BASIC INTRODUCTION

10
IMPORTING
•

It is a very good practice to separate your rules into different files instead of having a
1000 lines file.

•

Importing a file into another LESS is as simple as that:
• @import “file2.less”;

•

You can even omit the .less extension and just declare:

• @import “file2”;

LESS CSS - A BASIC INTRODUCTION

11
MODIFY VARIABLES
•

modifyVars enables modification of LESS variables in run-time.

•

When called with new value, the LESS file is recompiled without reloading.

•

Usage:
Less.modifyVars({
„@color1‟:‟red‟,

„@color2‟: „blue‟
});

LESS CSS - A BASIC INTRODUCTION

12
THANK YOU
•

References:
• Lesscss.org

• Verekia.com

LESS CSS - A BASIC INTRODUCTION

13

More Related Content

PPTX
.Less - CSS done right
PPT
PPTX
Less presentation
PDF
LESS CSS
PPTX
Less css
PPT
Why less?
PPTX
PPTX
Functional Css
.Less - CSS done right
Less presentation
LESS CSS
Less css
Why less?
Functional Css

What's hot (20)

PPTX
SASS - Syntactically Awesome Stylesheet
PPTX
ODP
Sass presentation
KEY
Intro to SASS CSS
PPTX
Bliblidotcom - SASS Introduction
PPTX
Journey To The Front End World - Part2 - The Cosmetic
ODP
Deep dive into sass
PPTX
Developer skills
PDF
The web context
PDF
Responsive Design in Drupal with Zen and Zen Grids
PPTX
Week01 jan19 introductionto_php
PDF
Intro to css & sass
KEY
Advanced sass
PPTX
Beautifying senc
PPTX
Web programming css
PPTX
SASS for WordPress Workshop
PPT
PPT
SharePoint 2010 branding
PDF
CSS Modules
SASS - Syntactically Awesome Stylesheet
Sass presentation
Intro to SASS CSS
Bliblidotcom - SASS Introduction
Journey To The Front End World - Part2 - The Cosmetic
Deep dive into sass
Developer skills
The web context
Responsive Design in Drupal with Zen and Zen Grids
Week01 jan19 introductionto_php
Intro to css & sass
Advanced sass
Beautifying senc
Web programming css
SASS for WordPress Workshop
SharePoint 2010 branding
CSS Modules
Ad

Similar to Start using less css (20)

PDF
Less(CSS Pre Processor) Introduction
PDF
LESS(CSS Pre Processor) introduction
PDF
CSS Less framework overview, Pros and Cons
PPTX
Doing More With Less
PDF
A better CSS: Sass and Less - CC FE & UX
PDF
LeSS in action
PPT
LESS(CSS preprocessor)
PPT
An Introduction to CSS Preprocessors (SASS & LESS)
PPTX
Write LESS. DO more.
PPTX
Less css framework
PDF
Do more with {less}
PPTX
Doing More with LESS for CSS
PDF
Get into less by tess hsu
PPTX
Introduction to LESS
PPTX
SASS is more than LESS
PDF
LESS is More
PDF
LESS is More (ChiHTML5 Meetup June 2016)
PDF
LESS CSS Pre-processor
PPTX
PPS
What is LessCSS and its Detailed Explation - Xhtmlchop
Less(CSS Pre Processor) Introduction
LESS(CSS Pre Processor) introduction
CSS Less framework overview, Pros and Cons
Doing More With Less
A better CSS: Sass and Less - CC FE & UX
LeSS in action
LESS(CSS preprocessor)
An Introduction to CSS Preprocessors (SASS & LESS)
Write LESS. DO more.
Less css framework
Do more with {less}
Doing More with LESS for CSS
Get into less by tess hsu
Introduction to LESS
SASS is more than LESS
LESS is More
LESS is More (ChiHTML5 Meetup June 2016)
LESS CSS Pre-processor
What is LessCSS and its Detailed Explation - Xhtmlchop
Ad

More from Ali MasudianPour (7)

ODP
An Introduction to REDIS NoSQL database
PPTX
Rapid postgresql learning, part 4
PPTX
Rapid postgresql learning, part 3
PPTX
Rapid postgresql learning, part 2
PPTX
Rapid postgresql learning, part 1
PDF
A comparison between C# and Java
PPTX
Xp exterme-programming-model
An Introduction to REDIS NoSQL database
Rapid postgresql learning, part 4
Rapid postgresql learning, part 3
Rapid postgresql learning, part 2
Rapid postgresql learning, part 1
A comparison between C# and Java
Xp exterme-programming-model

Recently uploaded (20)

PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
Teaching material agriculture food technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
KodekX | Application Modernization Development
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Approach and Philosophy of On baking technology
PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Big Data Technologies - Introduction.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Unlocking AI with Model Context Protocol (MCP)
Network Security Unit 5.pdf for BCA BBA.
Teaching material agriculture food technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
Spectral efficient network and resource selection model in 5G networks
Digital-Transformation-Roadmap-for-Companies.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation_ Review paper, used for researhc scholars
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
KodekX | Application Modernization Development
NewMind AI Weekly Chronicles - August'25 Week I
Approach and Philosophy of On baking technology
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Big Data Technologies - Introduction.pptx
MIND Revenue Release Quarter 2 2025 Press Release

Start using less css

  • 1. START USING LESS CSS By: Ali MasudianPour <masud.amp@gmail.com> LESS CSS - A BASIC INTRODUCTION 1
  • 2. WHAT IS LESS CSS • Dynamic CSS • Less is a “dynamic stylesheet language” • LESS extends CSS with dynamic behavior such as variables, mixins, operations and functions. • LESS runs on both the server-side (with Node.js and Rhino) or client-side (modern browsers only) LESS CSS - A BASIC INTRODUCTION 2
  • 3. COMPILING IN BROWSER • Less.js will perform AJAX requests to grab your Less files, will then process those files to convert them into CSS, and finally inject the resulting CSS in the head of your document. • There is a bad thing about it • if the user‟s JavaScript is deactivated, it will not work! LESS CSS - A BASIC INTRODUCTION 3
  • 4. LET‟S START • LESS codes are written into a file with .less extension • Variables • Less variables can be declared and used with the @ symbol. • Example: @white: #fff; .class{ background-color:@white; } LESS CSS - A BASIC INTRODUCTION 4
  • 5. LET‟S START • In addition, we can assign a variable to another • For instance: • • @myDefaultColor:@white; MIXINS • With Less we can define “mixins”, which are something comparable to functions in other programming languages. In Less they‟re used to group CSS instructions. .Round{ -webkit-border-radius:9999px; -moz-border-radius:9999px; border-radius:9999px; } #shape1{ .Round; } That‟s really simple! LESS CSS - A BASIC INTRODUCTION 5
  • 6. PARAMETRIC MIXINS • In LESS we can define parametric mixins. So we can send parameters through mixins • Example: @defaultRadius:30px; .RoundedShape(@radius:@defaultRadius){ -webkit-border-radius:@radius; -moz-border-radius:@radius; border-radius:@radius; } • What an incredible feature! LESS CSS - A BASIC INTRODUCTION 6
  • 8. OPERATIONS • One other powerful feature of Less is the ability to use mathematical operations in your stylesheets. • You can add, subtract, multiply and divide values • Example @defaultShapesWidth:200px; @borderSize:@defaultShapesWidth * 0.1; • it also works for colors @defaultThemeColor:@lightBlue; @borderColor:@defaultThemeColor - #222; LESS CSS - A BASIC INTRODUCTION 8
  • 9. COLOR FUNCTIONS • Less provides the following color functions: • darken() and lighten(), which add some black or white • saturate() and desaturate(), to make a color more colorful or more grayscale • Fadein() and fadeout, to increase or reduce transparency • Spin(), which modifies the hue of the color • Examples: @borderColor: desaturate(@defaultColor,100%) @borderColor: darken(desaturate($defaultColort,100%),20%) @defaultColor:spin(@mycolor1,100) LESS CSS - A BASIC INTRODUCTION 9
  • 10. NESTED RULES • When designing a complex page using css, you often have to chain selectors to aim a particular element in the DOM, like this: #header h1{} #main h1{} • With LESS you can nest rules inside parent rules to mimic the DOM structure: #header { h1{} } .shape{ } • &:hover{background-color:@myColor;} This & symbol represents the current selected elements. It is the equivalent of “THIS” in most programming language LESS CSS - A BASIC INTRODUCTION 10
  • 11. IMPORTING • It is a very good practice to separate your rules into different files instead of having a 1000 lines file. • Importing a file into another LESS is as simple as that: • @import “file2.less”; • You can even omit the .less extension and just declare: • @import “file2”; LESS CSS - A BASIC INTRODUCTION 11
  • 12. MODIFY VARIABLES • modifyVars enables modification of LESS variables in run-time. • When called with new value, the LESS file is recompiled without reloading. • Usage: Less.modifyVars({ „@color1‟:‟red‟, „@color2‟: „blue‟ }); LESS CSS - A BASIC INTRODUCTION 12
  • 13. THANK YOU • References: • Lesscss.org • Verekia.com LESS CSS - A BASIC INTRODUCTION 13