Sass Property Declarations

Beginner
⏱️ 15 min read
📚 Updated: Jul 2026
🎯 5 Examples
name: value

What You’ll Learn

Sass property declarations style matching elements like CSS—with SassScript values, nested prefixes, interpolated names, optional (hidden) declarations, and special rules for CSS custom properties. Five compiled examples follow.

01

Values

Any SassScript

02

#{ } names

Dynamic props

03

Nesting

font- / margin-

04

Hidden

null → omit

05

--custom

Interpolate only

06

Practice

5 examples

What Are Property Declarations?

Official docs: in Sass as in CSS, declarations define how elements that match a selector are styled. Sass makes them easier to write and automate—first and foremost, a declaration’s value can be any SassScript expression, evaluated into the CSS result.

  • Use variables, math, functions, and lists as values.
  • Nest related longhands under a shared prefix.
  • Build property names with #{ } when needed.
  • Skip emitting a property when its value is null (or an empty unquoted string).
💡
Beginner tip

For normal properties, write color: $brand;—not color: #{$brand};. Save interpolation for names, paths, and CSS custom properties.

📝 Syntax

styles.scss
.circle {
  $size: 100px;
  width: $size;
  height: $size;
  border-radius: $size * 0.5;
}

🔢 Interpolating Property Names

A property’s name can include interpolation so you can generate vendor prefixes or entire property identifiers dynamically.

🏷️ Nested Properties

Many CSS properties share a prefix namespace (font-, transition-, margin-). Nest the inner parts; Sass joins them with a hyphen.

For shorthands that use the same name as the namespace, you can write the shorthand value and nest more specific longhands underneath.

👁️ Hidden Declarations

If a declaration’s value is null or an empty unquoted string, Sass does not compile that declaration to CSS. Pair this with if($condition, $value, null) to toggle properties cleanly.

🎨 Custom Properties (--)

CSS custom properties allow almost any text as a value (and JS can read them). Because of that, Sass parses them differently: tokens that look like SassScript are passed through as-is. The only way to inject dynamic Sass values is interpolation.

⚠️
Heads up — quotes

Interpolation removes quotes from strings. To keep quoted lists (for example font stacks) intact inside --* properties, wrap the value with meta.inspect($value) inside #{ }.

Note: the plain-CSS @function result property is parsed like a custom property (interpolation required) in Dart Sass 1.94.0+. Older compilers (including many 1.69.x installs) may not support that API yet.

⚡ Quick Reference

GoalCode
Use a variablecolor: $brand;
Math in a valuewidth: $size * 0.5;
Nest a prefixfont: { size: 1rem; weight: 700; }
Shorthand + nestmargin: auto { top: 2px; }
Dynamic name#{$property}: $value;
Optional propertyborder-radius: if($on, 5px, null);
CSS variable from Sass--primary: #{$primary};
Keep quotes in ----fonts: #{meta.inspect($stack)};

Examples Gallery

Each example is verified with Dart Sass. Open View Compiled CSS for output.

📚 Getting Started

SassScript values and dynamic property names.

Example 1 — SassScript Values

Reuse a local variable and compute related sizes.

styles.scss
.circle {
  $size: 100px;
  width: $size;
  height: $size;
  border-radius: $size * 0.5;
}

How It Works

$size is a Sass variable scoped to the rule. Math runs at compile time; the CSS only contains final lengths.

Example 2 — Interpolated Property Names

Generate vendor-prefixed properties from a mixin.

styles.scss
@mixin prefix($property, $value, $prefixes) {
  @each $prefix in $prefixes {
    -#{$prefix}-#{$property}: $value;
  }
  #{$property}: $value;
}

.gray {
  @include prefix(filter, grayscale(50%), moz webkit);
}

How It Works

#{$prefix} and #{$property} build the property name. The value is normal SassScript (here a CSS grayscale() function).

📈 Nesting, Shorthands & Custom Props

Reduce repetition and bridge Sass tokens to CSS variables.

Example 3 — Nested transition-* Properties

Write the shared prefix once; Sass expands the longhands.

styles.scss
.enlarge {
  font-size: 14px;
  transition: {
    property: font-size;
    duration: 4s;
    delay: 2s;
  }

  &:hover { font-size: 36px; }
}

How It Works

transition: { property: … } becomes transition-property. Nested &:hover is a style rule, not a property nest.

Example 4 — Shorthand Plus Nested Longhands

Set margin: auto, then override specific sides.

styles.scss
.info-page {
  margin: auto {
    bottom: 10px;
    top: 2px;
  }
}

How It Works

The outer declaration emits the shorthand; nested keys become margin-bottom and margin-top.

Example 5 — Custom Properties & Hidden Values

Interpolate Sass into -- properties; omit a declaration with null.

styles.scss
@use "sass:meta";

$primary: #81899b;
$rounded-corners: false;
$font-family-sans-serif: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto;

:root {
  --primary: #{$primary};
  // Looks like Sass, but stays literal CSS text:
  --consumed-by-js: $primary;
  --font-family-sans-serif: #{meta.inspect($font-family-sans-serif)};
}

.button {
  border: 1px solid black;
  border-radius: if($rounded-corners, 5px, null);
}

How It Works

#{$primary} injects the color; bare $primary in a custom property is not evaluated. if(…, null) hides border-radius entirely.

🚀 Real-World Use Cases

  • Design tokens — compute sizes from one $space variable.
  • Vendor prefixes — mixin loops with interpolated property names.
  • Cleaner longhands — nest transition- / animation- groups.
  • Feature flags — emit radius/shadow only when a boolean is true.
  • Theme bridges — push Sass colors into :root { --* } for runtime CSS.

🧠 How Compilation Works

1

Read declaration

Resolve name (maybe #{ }) and choose custom-prop vs normal parsing.

Parse
2

Evaluate or pass through

Normal props run SassScript; --props need #{ } to inject.

Value
3

Expand nests

Join nested prefixes into full property names.

Nest
4

Emit or skip

Write CSS—or omit the line when the value is null.

⚠️ Common Pitfalls

  • --token: $sass-var; — does not substitute; use #{$sass-var}.
  • Quotes lost in -- — use meta.inspect when quotes matter.
  • Over-nesting — nesting properties is for prefixes, not for inventing invalid CSS names.
  • Expecting empty string tricks — only null / empty unquoted strings hide declarations.
  • color: #{$brand} — unnecessary for normal properties.

💡 Best Practices

✅ Do

  • Use SassScript freely for normal property values
  • Nest clear prefix families (font, margin, transition)
  • Interpolate when injecting into -- custom properties
  • Toggle optional CSS with if($flag, $value, null)
  • Prefer meaningful tokens over repeated magic numbers

❌ Don’t

  • Assume Sass variables auto-evaluate inside -- values
  • Build invalid CSS property names with nesting
  • Hide bugs by omitting properties accidentally with null
  • Wrap every value in #{ } “just in case”
  • Forget meta.inspect when quoted stacks must survive

Key Takeaways

Knowledge Unlocked

Five things to remember about property declarations

Values, names, nests, nulls, and custom properties.

5
Core concepts
🔢 02

#{ } names

dynamic props

Names
🏷️ 03

Nest prefixes

less repetition

Nest
👁️ 04

null hides

no CSS line

Optional
🎨 05

--needs #{ }

custom props

CSS vars

❓ Frequently Asked Questions

Like CSS, they set how matching elements look (color, width, and so on). Sass lets the value be any SassScript expression, and adds nesting, interpolation, and smarter custom-property parsing.
Write a shared prefix once, then nest the rest. transition: { property: font-size; } becomes transition-property: font-size. You can also set a shorthand and nest longhands under it.
Yes. Interpolate with #{ } in the property name, for example -#{$prefix}-#{$property}: $value; or even #{$property}: $value;
If the value is null or an empty unquoted string, Sass does not emit that declaration. Useful with if($flag, 5px, null).
Values are passed through almost as raw CSS. SassScript is not evaluated unless you use interpolation. So --x: $primary; keeps the text $primary; use --x: #{$primary}; to inject the variable.
Interpolation strips quotes from strings. Use meta.inspect($value) inside #{ } so quoted strings stay quoted in the CSS custom property.
Did you know?

Official Sass docs recommend using interpolation for custom property values even on older LibSass/Ruby Sass versions that once evaluated SassScript there—so your styles stay forward-compatible with modern Dart Sass parsing.

Conclusion

Sass property declarations extend CSS with expressive values, nested prefixes, optional output, and careful custom-property rules. Use SassScript for normal props and #{ } when the CSS text itself must change.

Continue with Sass Parent Selector or Sass Interpolation.

Next: Parent Selector

Nest with & for states, BEM names, and context.

Parent Selector →

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