Sass set-nth() Function

Last Updated:

Sass set-nth() Function

The set-nth() function returns a copy of a list with the element at the specified index replaced with a given value.

If the specified index value is negative, it counts from the end of a list. Throws an error if there is no existing element at the specified index.

Example

SASS TO CSS CONVERTER
.foo{ margin: set-nth(10px 20px 30px, 1, 2em); margin: set-nth(10px 20px 30px, -1, 8em); }

Syntax

set-nth($list, $n, $value)

Parameter Value

ValueTypeExplanation
$list Required Specifies a list.
$n Required Specifies the index value in the list.
  • If $n is positive, it counts from the start of $list.
  • If $n is negative, it counts from the end of $list.
  • Throws an error if there is no element at index $n.
$value Required Specifies the new value to replace the old value.

Return Value

ValueExplanation
list Returns a copy of $list with the element at index $n replaced with $value.

Share this Page

Meet the Author