LESS - Selectors



The selector can reference any variable and it is built during the compile time. The variable name must be placed inside the curly braces( { } ) prefixed with the @ symbol.


The following example demonstrates the use of selector in the LESS file −

      <link rel = "stylesheet" href = "style.css" type = "text/css" />
      <title>LESS selectors</title>
      <h2>Welcome to Tutorialspoint</h2>
      <div class = "div1">
         <p>LESS is a CSS pre-processor that enables customizable, 
            manageable and reusable style sheet for web site.</p>
      <div class = "div2">
         <p>LESS is a dynamic style sheet language that extends the capability of CSS. 
            LESS is also cross browser friendly.</p>

Now create the style.less file.


@selector: h2;

@{selector} {
   background: #2ECCFA;

You can compile the style.less to style.css by using the following command −

lessc style.less style.css

Execute the above command; it will create the style.css file automatically with the following code −


h2 {
   background: #2ECCFA;


Follow these steps to see how the above code works −

  • Save the above html code in the less_variables_interpolation_selectors.html file.

  • Open this HTML file in a browser, the following output will get displayed.

LESS Selectors