string.split() belongs to the built-in sass:string module. It turns one string into a list of pieces using a separator. This page covers the optional $limit, pairing with sass:list, and five compiled examples.
01
Concept
Split into a list
02
Module
@use "sass:string"
03
Returns
Bracketed list
04
Limit
Optional $limit
05
Needs
Dart Sass 1.57+
06
Practice
5 examples
Concept
What Is string.split()?
Official docs: returns a bracketed, comma-separated list of substrings of $string that are separated by $separator. The separators are not included in those substrings.
You get a list, not a single string—use list.nth or @each.
Optional $limit stops after a fixed number of splits.
When limited, the last piece keeps whatever is left (including leftover separators).
Requires Dart Sass 1.57+ (newer than most other sass:string helpers).
💡
Beginner tip
Picture cutting a sentence at every space. "Segoe UI Emoji" becomes the list ["Segoe", "UI", "Emoji"].
Foundation
📝 Syntax
styles.scss
@use "sass:string";
// Module API only (Dart Sass 1.57+)
string.split($string, $separator, $limit: null)
Parameters
Parameter
Type
Required
Description
$string
String
Yes
The text to split.
$separator
String
Yes
Where to cut (space, /, ,, --, …).
$limit
Number or null
No
Max number of separator cuts. Default null = split everywhere.
Return value
Type
Result
List
Bracketed, comma-separated list of substrings (separators removed)
Unlike str-length / str-slice, official docs do not provide a global str-split(). Use the module API on Dart Sass 1.57+.
Details
🎨 Official Patterns
Call
Result
split("Segoe UI Emoji", " ")
["Segoe", "UI", "Emoji"]
split("Segoe UI Emoji", " ", $limit: 1)
["Segoe", "UI Emoji"]
With $limit: 1, Sass cuts once. The second item keeps the remaining space and text.
Compare
⚖️ Understanding $limit
$limit
What happens
Max items
null (default)
Split on every separator
Unlimited
1 or higher
Split on at most that many separators
$limit + 1
💡
Remember the leftover
After the allowed cuts, the last substring contains the rest of the string, including any remaining separators. That is why "UI Emoji" still has a space.
Support
🛠 Compatibility
This is about Sass compilers, not browsers. Splitting happens at compile time.
Implementation
split
Dart Sass
Yes — string.split since 1.57.0
LibSass
No
Ruby Sass
No
Prefer current Dart Sass 1.57+. Other string helpers often need only 1.23+; split is newer.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Import string
@use "sass:string";
Split on spaces
string.split($s, " ")
Split once
string.split($s, " ", $limit: 1)
Get first piece
list.nth(string.split($s, "/"), 1)
Get last piece
list.nth(string.split($s, "/"), -1)
Loop pieces
@each $part in string.split($s, ",") { ... }
Hands-On
Examples Gallery
Each example uses string.split at compile time (Dart Sass 1.57+). Open View Compiled CSS for verified output.
📚 Getting Started
Official docs samples, then a font-family stack from parts.
Split turns the CSV into a list. @each walks every item and interpolates both the class name and the background value.
Applications
🚀 Real-World Use Cases
Font stacks — break a family string into individual names.
Path tooling — read folders and leaf names from / segments.
BEM helpers — cut once on -- to separate block vs modifiers.
Token loops — turn CSV-like strings into @each generators.
Config strings — parse simple space- or comma-delimited options at compile time.
🧠 How Compilation Works
1
Pass string and separator
Call string.split($string, $separator, $limit).
Source
2
Sass cuts into a list
Removes separators; applies $limit when set.
Compile
3
Use list helpers
Read with list.nth, count with list.length, or loop with @each.
Emit
4
✓
CSS ships
Browsers only see finished values like "Segoe" or red.
Watch Out
⚠️ Common Pitfalls
Expecting a string — the return value is a list.
Forgetting leftover separators — with $limit, the last item may still contain separators.
Old compilers — needs Dart Sass 1.57+; LibSass/Ruby Sass cannot run it.
Looking for str-split — there is no official legacy global name.
Confusing with string.slice — slice returns one substring; split returns many pieces.
Pro Tips
💡 Best Practices
✅ Do
Use @use "sass:string" and Dart Sass 1.57+
Pair with @use "sass:list" for nth / length
Use $limit when you only want the first cut
Inspect lists with meta.inspect while learning
Prefer clear separators (" ", "/", ",")
❌ Don’t
Treat the result like a single string
Forget that limited splits keep leftover separators
Expect LibSass or Ruby Sass support
Search for a global str-split()
Expect browsers to evaluate the call
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about string.split()
Cut a string into a bracketed list of pieces at compile time.
5
Core concepts
📝01
API
split(s, sep, limit)
Call
📦02
Module
sass:string
@use
🔗03
Result
bracketed list
Output
📚04
Limit
max cuts + leftover
Rule
✓05
Pair
list.nth / @each
Pattern
❓ 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. Official docs: 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 list (bracketed and comma-separated). Use list.nth, list.length, and @each to work with the pieces.
No. Official docs document only string.split on the sass:string module. Prefer @use "sass:string" and Dart Sass 1.57+.
Dart Sass 1.57+. LibSass and Ruby Sass do not support this function.
Did you know?
Official Sass docs show $limit: 1 turning "Segoe UI Emoji" into ["Segoe", "UI Emoji"]—proof that the leftover piece keeps remaining separators.
string.split() turns a string into a bracketed list of pieces. Separators are removed, optional $limit caps how many cuts happen, and the last leftover piece can still contain separators. Use list.nth and @each to work with the result on Dart Sass 1.57+.