<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/attempting-to-corral-colors-with-a-sass-function-nfvr2abey" -->

---
title: Attempting to corral colors with a Sass function | daily.dev
description: An exploration of using a custom Sass function (c()) paired with nested Sass maps to organize and control a website's color system across three levels: base...
canonical: https://daily.dev/posts/attempting-to-corral-colors-with-a-sass-function-nfvr2abey
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Attempting to corral colors with a Sass function | daily.dev
og:description: An exploration of using a custom Sass function (c()) paired with nested Sass maps to organize and control a website's color system across three levels: base...
og:url: https://daily.dev/posts/attempting-to-corral-colors-with-a-sass-function-nfvr2abey
og:image: https://api.daily.dev/og/posts/nfvR2ABEy.png
og:image:alt: Attempting to corral colors with a Sass function
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Attempting to corral colors with a Sass function

**[Eric Bailey](https://daily.dev/sources/ericwbailey)** · 16 min read · 0 upvotes · 0 comments

## Summary

An exploration of using a custom Sass function (c()) paired with nested Sass maps to organize and control a website's color system across three levels: base palette, component-level colors, and themes (e.g., dark mode or white-labeling). The approach aims to avoid 'variable chaining,' where colors are derived from other variables across files, by centralizing all color values in a single source-of-truth partial. Trade-offs discussed include team learning curve, extra repetitive code, difficulty retrofitting existing projects, and general unfamiliarity with Sass maps and map-get(). The piece closes by noting that CSS Custom Properties offer real-time updates and scoping that Sass variables lack, and suggests preferring them over Sass variables once browser support (e.g., IE11, Opera Mini) is no longer a concern.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://thoughtbot.com/blog/attempting-to-corral-colors-with-a-sass-function>

## Questions this post answers

### How can I organize colors in Sass to avoid variable chaining across multiple files?

Store all color values in a single nested Sass map (up to three levels: palette, component, theme) and access them through one custom function instead of chaining variables across partials. This keeps color definitions in one file, makes find-and-replace updates easy, and prevents unrelated components from accidentally reusing a modified color variable meant for a different context.

_daily.dev surfaces practical patterns like this for developers refining their Sass color architecture._

### Should I use CSS Custom Properties or Sass variables for theming a website?

CSS Custom Properties are preferable once browser support allows it, because unlike Sass variables they can be updated in real time with JavaScript and scoped per context, such as switching values inside a prefers-color-scheme media query. The main blocker is older browsers like Internet Explorer 11 and Opera Mini, which do not support CSS Custom Properties.

_Developers weighing Sass versus native CSS features for theming can track these trade-offs on daily.dev._

### How do I implement dark mode support for a component using Sass maps?

Add a nested dark-theme key inside a component's entry in the Sass color map containing only the overridden values, then reference it inside a prefers-color-scheme dark media query using a lookup function like c(tab, dark-theme, background). Themes should only override values that already exist at the component level, not introduce new ones, which Sass enforces by throwing a compilation error otherwise.

_daily.dev helps developers building dark mode features stay on top of practical Sass theming techniques._

## Similar posts on daily.dev

- [A few ways of specifying per-theme colours in only CSS — Chris Morgan](https://daily.dev/posts/a-few-ways-of-specifying-per-theme-colours-in-only-css-chris-morgan-yeihwzack) · Lobsters · 0 upvotes · 0 comments
- [Dynamic Colour Schemes With Modern CSS](https://daily.dev/posts/dynamic-colour-schemes-with-modern-css-unbd3csjb) · Always Twisted · 5 upvotes · 0 comments
- [Choosing colors \(for developers\)](https://daily.dev/posts/choosing-colors-for-developers--almguv7ft) · RUBYLAND · 7 upvotes · 4 comments
- [I’ve Changed My Mind About CSS Variables](https://daily.dev/posts/i-ve-changed-my-mind-about-css-variables-kkkpnjji7) · Aaron Gustafson · 5 upvotes · 1 comments

---

Tags: [#css](https://daily.dev/tags/css), [#design-systems](https://daily.dev/tags/design-systems)

[View this post on daily.dev](https://daily.dev/posts/attempting-to-corral-colors-with-a-sass-function-nfvr2abey)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Attempting to corral colors with a Sass function","url":"https://daily.dev/posts/attempting-to-corral-colors-with-a-sass-function-nfvr2abey","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/attempting-to-corral-colors-with-a-sass-function-nfvr2abey"},"datePublished":"2026-09-20T07:43:58.619Z","dateModified":"2026-09-20T07:46:22.669Z","description":"An exploration of using a custom Sass function (c()) paired with nested Sass maps to organize and control a website's color system across three levels: base...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5aa2c8ee3c2d5069da51cd064142e43c?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5aa2c8ee3c2d5069da51cd064142e43c?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Eric Bailey","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Eric Bailey","logo":"https://media.daily.dev/image/upload/s--r1vwe6z1--/f_auto,q_auto/v1789890198/logos/ericwbailey?_a=BAMAMicg0","url":"https://daily.dev/sources/ericwbailey"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/attempting-to-corral-colors-with-a-sass-function-nfvr2abey","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"css,design-systems","timeRequired":"PT16M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Eric Bailey","item":"https://daily.dev/sources/ericwbailey"},{"@type":"ListItem","position":3,"name":"Attempting to corral colors with a Sass function"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/attempting-to-corral-colors-with-a-sass-function-nfvr2abey#faq","mainEntity":[{"@type":"Question","name":"How can I organize colors in Sass to avoid variable chaining across multiple files?","acceptedAnswer":{"@type":"Answer","text":"Store all color values in a single nested Sass map (up to three levels: palette, component, theme) and access them through one custom function instead of chaining variables across partials. This keeps color definitions in one file, makes find-and-replace updates easy, and prevents unrelated components from accidentally reusing a modified color variable meant for a different context. daily.dev surfaces practical patterns like this for developers refining their Sass color architecture."}},{"@type":"Question","name":"Should I use CSS Custom Properties or Sass variables for theming a website?","acceptedAnswer":{"@type":"Answer","text":"CSS Custom Properties are preferable once browser support allows it, because unlike Sass variables they can be updated in real time with JavaScript and scoped per context, such as switching values inside a prefers-color-scheme media query. The main blocker is older browsers like Internet Explorer 11 and Opera Mini, which do not support CSS Custom Properties. Developers weighing Sass versus native CSS features for theming can track these trade-offs on daily.dev."}},{"@type":"Question","name":"How do I implement dark mode support for a component using Sass maps?","acceptedAnswer":{"@type":"Answer","text":"Add a nested dark-theme key inside a component's entry in the Sass color map containing only the overridden values, then reference it inside a prefers-color-scheme dark media query using a lookup function like c(tab, dark-theme, background). Themes should only override values that already exist at the component level, not introduce new ones, which Sass enforces by throwing a compilation error otherwise. daily.dev helps developers building dark mode features stay on top of practical Sass theming techniques."}}]}
```

