Home Sass List list.is-bracketed() Sass list.is-bracketed() Definition
Definition and Usage list.is-bracketed($list) returns true when $list uses square brackets ([…]), otherwise false . Load it with @use "sass:list" on Dart Sass 1.23+ . Global alias: is-bracketed().
Round parentheses do not count. Pair with list.join(..., $bracketed: …) when you create or force bracketed lists.
Official samples. list.is-bracketed(1px 2px 3px) → false. list.is-bracketed([1px, 2px, 3px]) → true.
Why it matters. CSS values like grid tracks often need square brackets. This helper lets mixins branch on that shape before emitting CSS.
Syntax
Syntax @use "sass:list";
list.is-bracketed(1px 2px 3px); // false
list.is-bracketed([1px, 2px, 3px]); // true
list.is-bracketed((1px, 2px, 3px)); // false — parentheses ≠ brackets
list.is-bracketed([]); // true
// Global alias still works
is-bracketed([1fr 2fr]); Pattern: inspect with is-bracketed → emit or rewrite with join(..., $bracketed: true) when brackets are required.
Code
SCSS Examples Examples target Dart Sass 1.23+ with @use "sass:list". Open View Compiled CSS for verified output (matches official Sass docs samples).
1. Plain list 2. Square 3. Shapes 4. Guard 5. join $bracketed Example 1 — Plain Space List Is Not Bracketed (Official Docs) A normal spacing list has no square brackets.
@use "sass:list";
@debug list.is-bracketed(1px 2px 3px); // false
.plain {
--bracketed: #{list.is-bracketed(1px 2px 3px)};
} .plain {
--bracketed: false;
} How It Works Space-separated values are a normal unbracketed list.Result is false .Boolean interpolates into the custom property.Matches the official Sass docs sample.Example 2 — Square Brackets Return true (Official Docs) Comma list written with […] is bracketed.
@use "sass:list";
@debug list.is-bracketed([1px, 2px, 3px]); // true
.square {
--bracketed: #{list.is-bracketed([1px, 2px, 3px])};
} .square {
--bracketed: true;
} How It Works Square brackets mark the list as bracketed.Separator can be comma — brackets are separate from separator.Result is true .Matches the official Sass docs sample.Example 3 — Empty Brackets, Singles, and Parentheses Edge shapes you will meet in real tokens.
@use "sass:list";
.report {
--space: #{list.is-bracketed(10px 20px 30px)};
--comma-brackets: #{list.is-bracketed([blue, red, green])};
--parens: #{list.is-bracketed((1px, 2px, 3px))};
--single: #{list.is-bracketed(10px)};
--empty: #{list.is-bracketed([])};
} .report {
--space: false;
--comma-brackets: true;
--parens: false;
--single: false;
--empty: true;
} How It Works Space / parentheses → false.Square comma list → true.Single value is an unbracketed one-item list.[] is empty but still bracketed → true.Example 4 — Branch Before Emitting Grid Tracks Only emit a value when the list is already bracketed.
@use "sass:list";
$plain: 8px 16px 24px;
$grid: [1fr 2fr 1fr];
.guard {
@if list.is-bracketed($grid) {
--grid-display: #{$grid};
} @else {
--grid-display: none;
}
@if list.is-bracketed($plain) {
--plain-display: #{$plain};
} @else {
--plain-kind: unbracketed;
}
} .guard {
--grid-display: [1fr 2fr 1fr];
--plain-kind: unbracketed;
} How It Works $grid is bracketed → emit the tracks.$plain is not → take the else path.@if keeps the check compile-time safe.Handy in mixins that accept either spacing or track lists.Example 5 — Force Brackets with list.join Create a bracketed list, then confirm with is-bracketed.
@use "sass:list";
@use "sass:meta";
$forced: list.join(10px, 20px, $bracketed: true);
.forced {
--joined: #{meta.inspect($forced)};
--is-bracketed: #{list.is-bracketed($forced)};
} .forced {
--joined: [10px 20px];
--is-bracketed: true;
} How It Works $bracketed: true on join adds square brackets.meta.inspect shows [10px 20px].is-bracketed confirms true.Use this when a plain list must become a CSS bracketed value. Edge Cases & Pitfalls Most is-bracketed bugs are confusing parentheses with square brackets or mixing up brackets with separators.
parens Parentheses ≠ brackets (1px, 2px, 3px) returns false. Only […] is bracketed.
sep Brackets ≠ separator A list can be space- or comma-separated and bracketed. Use list.separator for the separator name.
empty Empty [] is still bracketed list.is-bracketed([]) is true even though length is 0.
single Lone values are unbracketed 10px counts as a one-item list without brackets.
Toolchain
Sass Support Prefer the module form with Dart Sass 1.23+. Global is-bracketed() remains for older call sites.
API Status list.is-bracketed()Dart Sass 1.23+ via @use "sass:list" Global is-bracketed() Available (prefer module form in new code) Return type Boolean true / false LibSass / Ruby Sass No sass:list module — use global is-bracketed() if needed
Compile with the Dart Sass CLI .
Remember
Key Takeaways True only for square brackets […].
Parentheses and plain lists return false.
Pair with list.join $bracketed when you need to create brackets.
Prefer list.is-bracketed after @use "sass:list".
One line: when you need to know if a list uses […], call list.is-bracketed($list).
Practice
Compile Notes Practical checklist:
1. @use "sass:list"
2. Remember only square brackets count as bracketed
3. Do not confuse parentheses with brackets
4. Use list.join(..., $bracketed: true) to force brackets
5. Branch with @if list.is-bracketed($list) before emitting CSS Frequently Asked Questions What does Sass list.is-bracketed() do? list.is-bracketed($list) returns true if $list has square brackets, and false otherwise. Example: list.is-bracketed([1px, 2px, 3px]) is true; list.is-bracketed(1px 2px 3px) is false.
Do parentheses count as bracketed? No. Round parentheses are grouping/list syntax, not square brackets. list.is-bracketed((1px, 2px, 3px)) returns false.
Is an empty bracketed list still bracketed? Yes. [] is a bracketed list, so list.is-bracketed([]) is true.
How do single values behave? A lone value like 12px counts as a one-item list without brackets, so list.is-bracketed(12px) is false.
Can I still call is-bracketed() without the list. prefix? Yes. Global is-bracketed($list) still works. New projects should prefer list.is-bracketed() after @use "sass:list".
Which compilers support sass:list? Built-in modules with @use need Dart Sass 1.23+. LibSass and Ruby Sass do not load sass:list the same way—use the global is-bracketed() name there if you must.
Next: Sass list.join() Combine two lists, with optional separator and brackets.
list.join() → About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion