Sass list.is-bracketed()

Beginner
10 min read
Updated: Nov 2026
5 examples
Dart Sass 1.23+

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

SCSS
@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.

Bracket Rules

What counts as bracketed:

List shapeis-bracketed
[1px, 2px, 3px]true
1px 2px 3px / (1px, 2px, 3px)false
[]true (empty but bracketed)
Single value 10pxfalse
list.join(..., $bracketed: true)true
Parentheses are not brackets.

Comma lists written with (…) are unbracketed. Only square […] returns true.

SCSS Examples

Examples target Dart Sass 1.23+ with @use "sass:list". Open View Compiled CSS for verified output (matches official Sass docs samples).

Example 1 — Plain Space List Is Not Bracketed (Official Docs)

A normal spacing list has no square brackets.

SCSS
@use "sass:list";

@debug list.is-bracketed(1px 2px 3px); // false

.plain {
  --bracketed: #{list.is-bracketed(1px 2px 3px)};
}

How It Works

  1. Space-separated values are a normal unbracketed list.
  2. Result is false.
  3. Boolean interpolates into the custom property.
  4. Matches the official Sass docs sample.

Example 2 — Square Brackets Return true (Official Docs)

Comma list written with […] is bracketed.

SCSS
@use "sass:list";

@debug list.is-bracketed([1px, 2px, 3px]); // true

.square {
  --bracketed: #{list.is-bracketed([1px, 2px, 3px])};
}

How It Works

  1. Square brackets mark the list as bracketed.
  2. Separator can be comma — brackets are separate from separator.
  3. Result is true.
  4. Matches the official Sass docs sample.

Example 3 — Empty Brackets, Singles, and Parentheses

Edge shapes you will meet in real tokens.

SCSS
@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([])};
}

How It Works

  1. Space / parentheses → false.
  2. Square comma list → true.
  3. Single value is an unbracketed one-item list.
  4. [] is empty but still bracketed → true.

Example 4 — Branch Before Emitting Grid Tracks

Only emit a value when the list is already bracketed.

SCSS
@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;
  }
}

How It Works

  1. $grid is bracketed → emit the tracks.
  2. $plain is not → take the else path.
  3. @if keeps the check compile-time safe.
  4. 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.

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

$forced: list.join(10px, 20px, $bracketed: true);

.forced {
  --joined: #{meta.inspect($forced)};
  --is-bracketed: #{list.is-bracketed($forced)};
}

How It Works

  1. $bracketed: true on join adds square brackets.
  2. meta.inspect shows [10px 20px].
  3. is-bracketed confirms true.
  4. 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.

Sass Support

Prefer the module form with Dart Sass 1.23+. Global is-bracketed() remains for older call sites.

APIStatus
list.is-bracketed()Dart Sass 1.23+ via @use "sass:list"
Global is-bracketed()Available (prefer module form in new code)
Return typeBoolean true / false
LibSass / Ruby SassNo sass:list module — use global is-bracketed() if needed

Compile with the Dart Sass CLI.

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).

Compile Notes

Practical checklist:

checklist.txt
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

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.
No. Round parentheses are grouping/list syntax, not square brackets. list.is-bracketed((1px, 2px, 3px)) returns false.
Yes. [] is a bracketed list, so list.is-bracketed([]) is true.
A lone value like 12px counts as a one-item list without brackets, so list.is-bracketed(12px) is false.
Yes. Global is-bracketed($list) still works. New projects should prefer list.is-bracketed() after @use "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

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