Skip to content
⭐ Loving ngx-theme-stack? Support us with a star on GitHub!

Tailwind CSS v4 Integration

If you are using Tailwind CSS v4, you can map your themes.css variables directly to Tailwind design tokens. This gives you clean, theme-aware utility classes that update automatically — no dark: prefix needed.

Ensure your themes are defined in src/themes.css. This file is managed by ngx-theme-stack:

src/themes.css
:root {
--bg-color: #ffffff;
--text-color: #1a1a1a;
--card-bg: #f3f4f6;
}
[data-theme='dark'] {
--bg-color: #0f172a;
--text-color: #f8fafc;
--card-bg: #1e293b;
}

In your src/styles.css, expose your theme variables as Tailwind tokens:

src/styles.css
@import 'tailwindcss';
@theme {
--color-main-bg: var(--bg-color);
--color-main-text: var(--text-color);
--color-card-bg: var(--card-bg);
}
<div class="bg-main-bg text-main-text shadow-xl">
<!-- automatically reflects the active theme (dark, light, sunset, etc.) -->
</div>

Only needed if you want to use dark: utilities tied to ngx-theme-stack’s toggle (e.g. dark:bg-black).

src/styles.css
@import 'tailwindcss';
/* Class mode */
@custom-variant dark (&:where(.dark, .dark *));
/* Attribute mode */
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));