Sass meta.keywords() Function

Intermediate
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
sass:meta · $args...

What You’ll Learn

meta.keywords() belongs to the built-in sass:meta module. It reads the named arguments from an argument list created with $args... and returns them as a map. This page covers argument lists, keyword maps, the official syntax-colors pattern, and five compiled examples.

01

Concept

Named args → map

02

Module

@use "sass:meta"

03

Input

Argument list

04

Returns

Map of keywords

05

Keys

Names without $

06

Practice

5 examples

What Is meta.keywords()?

When a mixin or function accepts $args..., callers can pass a mix of positional values and named keywords like $string: #080. Official docs: meta.keywords($args) returns only those keywords as a map from unquoted name strings (without $) to their values.

💡
Beginner tip

Think of $args... as a bag of everything the caller sent. meta.keywords pulls out the labeled sticky notes (named args) and ignores unlabeled items (positional args).

📝 Syntax

styles.scss
@use "sass:meta";

// Recommended
meta.keywords($args)

// Legacy global name
keywords($args)

Parameters

ParameterTypeRequiredDescription
$argsArgument listYesMust be an argument list—typically from $args... on a mixin or function.

Return value

TypeResult
MapKeyword names (unquoted strings, no $) → argument values. Empty map if no keywords were passed.

📦 Argument Lists and $args...

You almost always use keywords inside a mixin or function that ends with a rest parameter:

styles.scss
@use "sass:meta";

@mixin demo($args...) {
  // $args is an argument list (not a plain list)
  $named: meta.keywords($args);
  // loop $named with @each ...
}

@include demo($color: teal, $gap: 1rem);
  • Positional values remain available on the argument list itself.
  • Keyword entries are collected into the map from meta.keywords.
  • Map keys never include the $ prefix.

📦 Loading sass:meta

styles.scss
// Recommended — namespaced
@use "sass:meta";
@mixin m($args...) {
  $k: meta.keywords($args);
}

// Optional — bring members into scope
@use "sass:meta" as *;
@mixin m($args...) {
  $k: keywords($args);
}

// Legacy global
@mixin m($args...) {
  $k: keywords($args);
}

🛠 Compatibility

This is about Sass compilers, not browsers. Keyword extraction runs at compile time.

Implementationkeywords
Dart SassYes — prefer meta.keywords
LibSassYes (legacy global / pipelines)
Ruby SassYes (legacy global / pipelines)

Prefer current Dart Sass with @use "sass:meta".

⚡ Quick Reference

GoalCode
Import meta@use "sass:meta";
Accept any named args@mixin name($args...) { … }
Get keyword mapmeta.keywords($args)
Loop keywords@each $name, $value in meta.keywords($args) { … }
Check a keymap.has-key(meta.keywords($args), "debug")
RememberKeys omit $; positionals are not in the map

Examples Gallery

Each example uses meta.keywords on an argument list. Open View Compiled CSS for verified Dart Sass output.

📚 Getting Started

Official syntax-colors sample and a quick map peek.

Example 1 — Syntax Colors (Official Docs)

Turn named color keywords into generated selectors.

styles.scss
@use "sass:meta";

@mixin syntax-colors($args...) {
  @each $name, $color in meta.keywords($args) {
    pre span.stx-#{$name} {
      color: $color;
    }
  }
}

@include syntax-colors(
  $string: #080,
  $comment: #800,
  $variable: #60b
);

How It Works

meta.keywords($args) becomes a map like (string: #080, comment: #800, variable: #60b). @each walks each pair and builds a class from the key name.

Example 2 — Peek at the Keywords Map

Use meta.inspect to see the map shape while learning.

styles.scss
@use "sass:meta";

@mixin peek($args...) {
  .peek {
    --keys: #{meta.inspect(meta.keywords($args))};
  }
}

@include peek($a: 1, $b: 2);

How It Works

Named args become map entries with bare keys a and b. Prefer @debug in real projects; this peek is for learning.

📈 Practical Patterns

Empty keywords, mixed positionals, and optional flags.

Example 3 — No Keywords → Empty Map

Positional-only calls still work; the keyword map is empty.

styles.scss
@use "sass:meta";

@mixin peek($args...) {
  .peek {
    --keys: #{meta.inspect(meta.keywords($args))};
  }
}

@include peek(1, 2, 3);

How It Works

1, 2, 3 are positional only, so meta.keywords returns an empty map (). Positionals are not copied into the keyword map.

Example 4 — Fixed Arg + Keyword Bag

Keep a required positional parameter, then spread extra named styles.

styles.scss
@use "sass:meta";

@mixin box($pad, $args...) {
  .box {
    padding: $pad;
    @each $name, $val in meta.keywords($args) {
      #{$name}: $val;
    }
  }
}

@include box(1rem, $color: teal, $border-radius: 8px);

How It Works

$pad is handled normally. Remaining named args land in meta.keywords($args) and become CSS declarations via interpolation.

Example 5 — Detect an Optional Keyword Flag

Combine meta.keywords with map.has-key.

styles.scss
@use "sass:meta";
@use "sass:map";

@function has-kw($args...) {
  @return map.has-key(meta.keywords($args), "debug");
}

.flag {
  --debug: #{has-kw($debug: true, $x: 1)};
}

How It Works

The key is the bare name debug (from $debug). map.has-key reports whether that optional flag was passed.

🚀 Real-World Use Cases

  • Flexible theme APIs — accept any named tokens without listing every parameter.
  • Code generators — official syntax-highlighter color maps.
  • Property bags — spread leftover keywords into CSS declarations.
  • Optional flags — detect $debug / $verbose with map.has-key.
  • Library helpers — separate required positionals from open-ended options.

🧠 How Compilation Works

1

Caller passes named args

Example: @include m($string: #080, $comment: #800).

Source
2

Rest param collects an argument list

$args... receives positionals + keywords together.

Compile
3

meta.keywords builds a map

Named args become (name: value, …) with bare keys.

Map
4

You loop and emit CSS

@each turns map entries into selectors or properties.

⚠️ Common Pitfalls

  • Passing a plain list/map$args must be an argument list from $args....
  • Looking for $ in keys — keys are bare names like string, not $string.
  • Expecting positionals in the map — they stay on the argument list only.
  • Interpolating unsafe names — keyword keys used as CSS must be valid identifiers/properties.
  • Confusing with CSS keywords — this is about Sass named arguments, not CSS reserved words.

💡 Best Practices

✅ Do

  • Use @use "sass:meta" and meta.keywords()
  • Pair with $args... on flexible mixins/functions
  • Loop with @each $name, $value in …
  • Keep required parameters separate from the rest bag
  • Validate optional flags with map.has-key

❌ Don’t

  • Pass ordinary lists into meta.keywords
  • Assume every caller will pass keywords
  • Put $ into map key lookups
  • Emit arbitrary keys as CSS without checks
  • Expect browsers to evaluate meta.keywords

Key Takeaways

Knowledge Unlocked

Five things to remember about meta.keywords()

Pull named arguments out of an $args... list as a map.

5
Core concepts
📦 02

Module

sass:meta

@use
📚 03

Input

argument list

$args...
🔗 04

Returns

keyword map

Result
05

Keys

no $ prefix

Rule

❓ Frequently Asked Questions

meta.keywords($args) returns a map of the keyword (named) arguments passed into a function or mixin that accepts arbitrary arguments via $args....
An argument list—usually the rest parameter from @mixin name($args...) or @function name($args...). Passing a normal list or map is not the same thing.
Official docs: keys are unquoted strings of argument names without the $. So $string: #080 becomes the map key string (the name without $).
No. keywords() only returns named keyword arguments. Positional values stay in the argument list itself.
Yes. keywords($args) is the legacy global name. Prefer meta.keywords after @use "sass:meta".
Flexible APIs that accept any set of named options—theme tokens, syntax highlighters, or property bags—then loop the map with @each.
Did you know?

Official Sass docs use meta.keywords to power a tiny syntax theme API: pass $string, $comment, and $variable colors, then generate .stx-* rules automatically from the returned map.

Conclusion

meta.keywords() turns named arguments from an $args... argument list into a map you can loop, inspect, or query. Keep required parameters separate, remember keys omit $, and use this pattern for flexible Sass APIs.

Continue with meta.load-css() or the Sass introduction.

Next: load module CSS

Learn meta.load-css() to include another file’s CSS anywhere.

meta.load-css() →

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.

5 people found this page helpful