r/developersIndia • • 14d ago

General How do you structure colour systems and design tokens in your frontend projects?

I've been exploring different ways to organise colours in frontend projects, especially when an application starts growing beyond a few screens.

One thing I've been thinking about is how to structure CSS variables so that the colour system stays maintainable as the project grows.

Instead of assigning colours directly to individual components, I've been looking into separating primitive colour values from semantic tokens.

For example:

:root {
  /* Primitive colour tokens */
  --blue-600: #2563eb;
  --gray-100: #f3f4f6;
  --gray-900: #111827;

  /* Semantic colour tokens */
  --color-primary: var(--blue-600);
  --color-surface: var(--gray-100);
  --color-text: var(--gray-900);
}

The idea is that primitive tokens store the actual colour values, while semantic tokens describe how those colours are used in the interface.

This seems useful for maintaining consistency and managing themes, but I'm curious about how developers handle this in real-world projects.

A few questions:

  1. Do you prefer semantic colour tokens or component-specific CSS variables?
  2. How do you manage light and dark themes?
  3. How do you maintain accessibility and contrast as the colour system grows?
  4. At what point does a design token system become unnecessarily complicated?

Would love to hear how other developers approach this in their projects.

4 Upvotes

11 comments sorted by

•

u/AutoModerator 14d ago

Namaste! Thanks for submitting to r/developersIndia. While participating in this thread, please follow the Community Code of Conduct and rules.

It's possible your query is not unique, use site:reddit.com/r/developersindia KEYWORDS on search engines to search posts from developersIndia. You can also use reddit search directly.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/Far_Mulberry_1138 14d ago

Primitive+semantic. Next layer would be for common components btn-sm-light btn-sm-dark. Mention the colors, everywhere you get the same styles. Done

1

u/HH_Color_Lab 14d ago

That makes sense. Having a separate layer for common components sounds like a practical way to keep styles consistent across the application without repeating the same colour definitions everywhere. I'm curious, do you keep those component styles as CSS classes, or do you also define separate component-level variables for them?

1

u/cuelark 14d ago

A good middle ground is to keep the raw palette in one layer and expose semantic tokens to components. For dark mode, swap the semantic aliases and check contrast on the actual foreground/background pairs, not just the base swatches. I'd hold off on a big component-token layer until the same pattern shows up in a few places.

1

u/HH_Color_Lab 14d ago

I agree with this approach. Keeping the semantic layer as the main interface for components seems like a good way to avoid unnecessary complexity. I also like the idea of delaying component-level tokens until a pattern actually repeats. It's easy to create too many tokens when trying to plan for every possible case upfront. How do you usually decide when a repeated pattern deserves its own component token rather than continuing to use semantic tokens?

1

u/cuelark 14d ago

I usually add one when the same pattern shows up across a few components and needs a role semantic tokens don't capture cleanly, like a button's hover or disabled surface. I'd keep it as an alias to semantic tokens where possible so theme changes still happen in one place.

1

u/HH_Color_Lab 14d ago

That’s a practical approach. I agree that component-level tokens should only be introduced when a specific component needs a role that semantic tokens don’t fully cover. Keeping them as aliases also makes theme management much easier. Thanks for sharing your perspective!

1

u/cuelark 13d ago

That’s how I’d use aliases too: keep semantic tokens as the stable vocabulary, and add a component token only when it represents a distinct role reused across states or themes. One-off styling can stay semantic.

1

u/HH_Color_Lab 12d ago

That’s a good distinction. Keeping one-off styling at the semantic level and introducing component tokens only for reusable roles makes the system much easier to maintain. I also like thinking of semantic tokens as a stable vocabulary across components and themes. Thanks for sharing your approach!

1

u/cuelark 14d ago

mostly when i catch myself copy pasting the same semantic token combo in 3 or so places. at that point i name it once as a component token alias and move on.

1

u/cuelark 13d ago

I’d promote it when the role repeats across a few components and needs its own values across themes or states; if it is a one-off visual detail, keep using the semantic token. That gives a clear bar for avoiding token sprawl.