🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Astro Themes••By Komal Nakrani

Change Astro Theme Colors in One Place

How to change Astro theme colors the right way: edit the Tailwind palette or CSS variables once, catch hard-coded hex values, and keep dark mode readable.

#Astro#Theme Colors#Tailwind CSS#Astro Themes

To change Astro theme colors, find where the theme defines its palette, usually tailwind.config.mjs or a block of CSS custom properties in src/styles/global.css, and edit the values there. Every component that uses those tokens picks up the new colors on the next reload. Then search for hard-coded hex values the theme author missed, and check contrast in both light and dark mode.

Key Takeaways

  • Change colors at the token level (Tailwind config or CSS variables), never class by class.
  • Keep the theme’s token names (brand, accent, surface) and change only their values.
  • Grep for stray hex values after the swap; they are the usual reason a color “won’t change”.
  • Re-check contrast: body text needs at least 4.5:1 against its background.

Find where the theme defines colors

Open the project and look in these places, in order:

# Terminal: run from the theme root
ls tailwind.config.* 2>/dev/null
grep -rn "@theme\|--color-" src/styles/ | head -20

A Tailwind CSS 3 theme keeps its palette in tailwind.config.mjs. A Tailwind CSS 4 theme keeps it in CSS inside an @theme block. A theme without Tailwind uses plain custom properties on :root. The styling and design tokens docs show where Komal themes keep theirs.

Change colors in Tailwind CSS 3

Edit the values under theme.extend.colors. Leave the key names alone, because components reference them as bg-brand, text-brand-dark and so on:

// tailwind.config.mjs
/** @type {import('tailwindcss').Config} */
export default {
  content: ['./src/**/*.{astro,html,js,ts,md,mdx}'],
  theme: {
    extend: {
      colors: {
        brand: {
          DEFAULT: '#0f766e',
          light: '#ccfbf1',
          dark: '#134e4a',
        },
        ink: '#111827',
      },
    },
  },
};

If the dev server is running, the change shows up on save. If it doesn’t, stop and restart npm run dev; config files are read at startup.

Change colors in CSS custom properties

Themes with a dark mode often store colors as variables and swap them with a class or data attribute. Change both sets:

/* src/styles/global.css */
:root {
  --color-brand: #0f766e;
  --color-surface: #ffffff;
  --color-text: #111827;
}

:root[data-theme='dark'] {
  --color-brand: #5eead4;
  --color-surface: #0b1120;
  --color-text: #e5e7eb;
}

In Tailwind CSS 4 the same idea lives in @theme, and the variable names become utilities (--color-brand gives you bg-brand):

/* src/styles/global.css */
@import 'tailwindcss';

@theme {
  --color-brand: #0f766e;
  --color-brand-dark: #134e4a;
}

The design tokens with CSS variables guide covers how to structure a palette so one edit reaches every component.

Catch the colors that didn’t change

Theme authors sometimes hard-code a color in a component, an SVG, or a <meta name="theme-color"> tag. Search for the old values:

# Terminal: list hex colors outside the token files
grep -rnoE "#[0-9a-fA-F]{6}\b" src --include=*.astro --include=*.css --include=*.svg | sort | uniq -c | sort -rn | head

Replace each hit with the matching token (text-brand, var(--color-brand)). Also check public/ for a web manifest with theme_color, and inline SVG icons that use fill="#..." instead of currentColor.

Check contrast and dark mode

A new brand color can look fine on a button and fail as link text. Test the pairs that matter: body text on the page background, button text on the brand color, and links on both surfaces, in light and dark mode. Browser DevTools shows the contrast ratio when you inspect a text element. If the theme has a toggle, the Tailwind dark mode tip explains how the class or attribute switch works.

If you’re starting from a Komal theme, every one of the Astro themes in the catalog defines its palette in one place, so a rebrand is a single-file change. For general styling options, see the official Astro styling guide.

FAQ

Why won’t my Astro theme colors change?

Usually the color is hard-coded in a component instead of using a token, or the Tailwind config change hasn’t been picked up. Restart the dev server, then grep for the old hex value in src/.

Can I change Astro theme colors without Tailwind?

Yes. Themes without Tailwind use CSS custom properties or scoped <style> blocks. Change the variables in the global stylesheet, and any component reading var(--color-brand) updates.

How do I pick a color palette for a theme?

Start from one brand color, then derive a light tint for backgrounds and a dark shade for hover states and text. Check every text and background pair for a contrast ratio of at least 4.5:1 before you ship.