⊗mkLsBsFOP 23 of 41 menu

Optional parameter in functions in LESS

Parameters in functions can be optional. To do this, they need to be given a default value. In this case, when calling the function, we can omit the parameter value - and the specified default value will be taken. Let's look at an example.

Let's say we have a function that sets the color of an element:

.color(@c) { color: @c; }

Let's make the color parameter optional and have the default value red:

.color(@c: red) { color: @c; }

Let's now call our function with a parameter:

div { .color(green); }

Now let's call our function without a parameter:

div { .color(); }
enru