less
  1. less-list-functions

List Functions - (Less Functions)

List functions are used in Less, which is a popular CSS pre-processor. They are used to manipulate and apply operations on lists. In this tutorial, we'll cover the syntax, examples, output, explanation, use, important points, and summary of some commonly used list functions in Less.

Syntax

The syntax for using list functions in Less is as follows:

functionName(list)

Where functionName is the name of the function and list is the list to which the function should be applied.

Example

Let's look at some examples of using list functions in Less:

@list1: 10px 20px 30px;
@list2: 40px 50px 60px;
@concatenatedList: concat(@list1, @list2);

@roundedNumbers: round-list(0.5, 1.2, 3.6, 2.4, 5.9, 6.3);

In this example, we are using the concat() and round-list() functions.

The concat() function combines two or more lists into a new list. The round-list() function rounds all the values in a list to the nearest whole number.

Output

The output of the concat() function in our example would be a new list that contains all the values from @list1 and @list2, as shown below:

10px 20px 30px 40px 50px 60px

The output of the round-list() function in our example would be a new list that contains all the rounded values, as shown below:

1 1 4 2 6 6

Explanation

In the first example, we used the concat() function to combine @list1 and @list2 into a single list called @concatenatedList.

In the second example, we used the round-list() function to round all the values in the list to the nearest whole number.

Use

List functions in Less are used to apply operations on lists. They can help simplify your Less code and make it easier to work with lists.

Important Points

  • There are many list functions available in Less, including concat(), length(), join(), append(), map(), and extract().
  • List functions can be nested to apply multiple operations to the same list.
  • Some list functions require additional parameters, such as a separator for join() or a mapping function for map().
  • List functions can be used to manipulate values in a list or to create a new list based on an existing list.

Summary

In this tutorial, we covered some commonly used list functions in Less. We looked at the syntax, examples, output, explanation, use, and important points of list functions, and how they can be used to manipulate and apply operations on lists in Less. With this knowledge, you can now use list functions in your own Less code to help simplify your code and make it easier to work with lists.

Published on: