Sass string.split()

Beginner
8 min read
Updated: Nov 2026
5 examples
Dart Sass 1.57+

Definition and Usage

string.split($string, $separator, $limit: null) returns a bracketed, comma-separated list of substrings of $string split on $separator. Separators are not included. Load with @use "sass:string".

Official sample idea.

string.split("Segoe UI Emoji", " ") becomes ["Segoe", "UI", "Emoji"].

Optional limit.

With $limit: 1 or higher, Sass splits on at most that many separators; the last item keeps the remainder.

Newer API.

string.split needs Dart Sass 1.57+—newer than most other sass:string helpers (1.23+).

Syntax

SCSS
@use "sass:string";

string.split($string, $separator, $limit: null) //=> list

string.split("Segoe UI Emoji", " ");
// ["Segoe", "UI", "Emoji"]

string.split("Segoe UI Emoji", " ", $limit: 1);
// ["Segoe", "UI Emoji"]

// No legacy global name — module API only
// Prefer @use "sass:string" (Dart Sass 1.57+)

Pattern: pick a separator → get a list of parts → walk with @each or list.nth.

Limit Behavior

How $limit changes the result:

LimitBehavior
null (default)Split on every separator
1 or higherSplit on at most that many separators
Max itemsAt most $limit + 1 substrings
Last itemKeeps the rest of the string, including leftover separators

SCSS Examples

Examples use @use "sass:string". Open View Compiled CSS for verified Dart Sass output (matches official Sass docs samples where shown).

Example 1 — Official Split Samples

Full split vs a single-separator limit.

SCSS
@use "sass:meta";
@use "sass:string";

.probe {
  --all: #{meta.inspect(string.split("Segoe UI Emoji", " "))};
  --limit: #{meta.inspect(string.split("Segoe UI Emoji", " ", $limit: 1))};
}

How It Works

  1. Space separator yields three parts.
  2. $limit: 1 stops after one split.
  3. Last item keeps "UI Emoji".
  4. Matches the official Sass docs samples.

Example 2 — Multi-Character Separator + Limit

Split on "--" fully, then once with a limit.

SCSS
@use "sass:meta";
@use "sass:string";

$full: string.split("a--b--c", "--");
$once: string.split("a--b--c", "--", $limit: 1);

.compare {
  --full: #{meta.inspect($full)};
  --once: #{meta.inspect($once)};
}

How It Works

  1. Multi-char separator works like a single char.
  2. Full split drops every --.
  3. Limit 1 leaves b--c intact.
  4. Useful for BEM-like token parsing.

Example 3 — Pick a Part with list.nth

Split a class-like string, then read one item and the count.

SCSS
@use "sass:list";
@use "sass:meta";
@use "sass:string";

$parts: string.split("btn primary large", " ");
$mod: list.nth($parts, 2);

.btn {
  --mod: #{meta.inspect($mod)};
  --count: #{list.length($parts)};
}

How It Works

  1. split builds a three-item list.
  2. list.nth(..., 2) picks the modifier.
  3. list.length reports how many parts.
  4. Bridge from string APIs to list APIs.

Example 4 — Walk Parts with @each

Emit a custom property for each split token.

SCSS
@use "sass:meta";
@use "sass:string";

$parts: string.split("Segoe UI Emoji", " ");

.loop {
  @each $part in $parts {
    --p-#{$part}: #{meta.inspect($part)};
  }
}

How It Works

  1. split returns a list.
  2. @each walks every part.
  3. Interpolation builds property names.
  4. inspect keeps quote state visible.

Example 5 — Generate Classes from Tokens

Turn a space-separated token string into utility rules.

SCSS
@use "sass:string";

$tokens: string.split("primary accent muted", " ");

@each $token in $tokens {
  .chip-#{$token} {
    content: $token;
  }
}

How It Works

  1. One string holds design tokens.
  2. split turns it into a list.
  3. @each emits a rule per token.
  4. Scales config written as plain text.

Edge Cases & Pitfalls

Most split bugs are wrong limits or treating the result like a string.

list

Result is a list, not a string

Use list.nth, list.length, or @each—not string helpers on the whole result.

limit

Limit counts separators, not items

$limit: 1 means one split → up to two parts; leftover separators stay in the last item.

brackets

Bracketed comma list

meta.inspect shows ["a", "b"]—that bracketed form is intentional.

version

Needs Dart Sass 1.57+

Older toolchains may miss string.split even if other sass:string helpers work.

Sass Support

Module-only API on current Dart Sass.

APIStatus
string.split()Dart Sass 1.57+ via @use "sass:string"
Return typeBracketed, comma-separated list
SeparatorsNot included in the substrings
Legacy globalNone — no str-split()

Compile with the Dart Sass CLI.

Key Takeaways

  • Returns a bracketed list of substrings.
  • $limit caps splits — last item keeps the remainder.
  • Pair with list APIs — nth, length, @each.
  • Dart Sass 1.57+ — no legacy global name.

One line: to turn a string into a list of parts, use string.split($string, $separator).

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:string" (Dart Sass 1.57+)
2. Pass $string and $separator
3. Expect a bracketed comma-separated list
4. Use $limit when you need a head / remainder split
5. Walk results with @each or list.nth / list.length

Frequently Asked Questions

string.split($string, $separator, $limit: null) returns a bracketed, comma-separated list of substrings split on $separator. Example: string.split("Segoe UI Emoji", " ") is ["Segoe", "UI", "Emoji"].
No. The separators are not included in the substrings.
If $limit is a number 1 or higher, Sass splits on at most that many separators and returns at most $limit + 1 strings. The last substring keeps the rest of the string, including remaining separators. Example: string.split("Segoe UI Emoji", " ", $limit: 1) is ["Segoe", "UI Emoji"].
A bracketed, comma-separated list. Use list.nth, list.length, and @each to work with the pieces.
No. Official docs document only string.split on the sass:string module.
Dart Sass 1.57+. LibSass and Ruby Sass do not support this function.

Next: Sass string.to-lower-case()

Convert ASCII letters in a string to lower case.

string.to-lower-case() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful