Sass set-nth() Function

You are Here:

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.


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


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

Parameter Value

$listRequiredSpecifies a list.
$nRequiredSpecifies 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.
$valueRequiredSpecifies the new value to replace the old value.

Return Value

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


Hi Developers, we almost covered 99.1% of Sass Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in Sass.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author