Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Andrew Sena
Andrew Sena
7,851 Points

Can someone please explain to me what LESS is and how its used? I know it has something to do with CSS that's it though.

I'm mainly just very curious of how it is connected to CSS.

2 Answers

Ryan Field
PLUS
Ryan Field
Courses Plus Student 21,242 Points

I use Sass myself, but it's the same basic idea.

What happens when you use a CSS preprocessor is that you break up your code into different sections (such as 'modules', 'layout', 'variables', etc) to write your code. Every time you save a file, LESS recompiles your code into a single stylesheet.

In terms of what it allows you to do, like Jesus said, it makes your CSS more maintainable and extendable.

As an example, say you have a site and a designer has chosen a particular colour palette. With regular CSS, you would have to copy and paste those colours (#13ea43, for example) everywhere that you want that colour to appear. Then, if a change is made later on and someone decides to use a different colour, you have to replace every single instance of that colour. With LESS, however, you can create a variable ($main-color: #13ea43, for example) and then just use that variable name wherever you want it to appear. Then if someone decides to change that colour later, you simply have to replace the variable value with the new value and it will take care of the rest for you. More complicated examples include entire element styles (box shadows, border radii, background colours, etc) that can be used in several locations and easily modified without copying and pasting everywhere. LESS also allows you to use functions and conditional statements (these are only available prior to compiling, however), which makes writing CSS quite a bit faster.

There's a lot more that preprocessors can do, but if you are serious about front-end design, it's definitely something to look into and learn. I don't think I can go back to regular CSS now! :)

Andrew Sena
Andrew Sena
7,851 Points

Thank you Ryan, I'll be sure to look into it.

Jesus Mendoza
Jesus Mendoza
23,289 Points

Definition from their Web Page

Less is a CSS pre-processor, meaning that it extends the CSS language, adding features that allow variables, mixins, functions and many other techniques that allow you to make CSS that is more maintainable, themable and extendable.