Less convert

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Less convert()

The Less convert function is used to convert number from one unit to another. It contains two arguments; first argument passes number along with unit and second argument contains units. The number is converted when the unit is compatible.

If the first argument is unchanged then the unit is not compatible.

Let's take an example to demonstrate the usage of convert function in Less.

Create a Less file named "simple.less", having the following data.

Less file: simple.less

  1. body{  

  2.   meter:convert(10cm, mm);  

  3.   time:convert(3s, "ms");  

  4.   no-unit:convert(5, mm);  

  5. }   

Now, execute the following code: lessc simple.less simple.css

Less-convert-function1"/

This will compile the "simple.less" file. A CSS file named "simple.css" will be generated.

For example:

Less-convert-function2"/

Output:

Less-convert-function3"/