In my global css file where I import:

@tailwind base;
@tailwind components;
@tailwind utilities;

I moved this piece of code below body{...} and everything works now

body {
    font-family: "DIN Alternate", sans-serif;
    font-size: 16px;
}

@tailwind base;
@tailwind components;
@tailwind utilities;

To the first thing you should check if the same error occured is how you import tailwind css

I moved body to the bottom since fonts didn't work and it WORKED. Weird problem. I think tailwind just needed some refresh in styles UPD:

@tailwind base;
@tailwind components;
@tailwind utilities;

body {
    font-family: "DIN Alternate", sans-serif;
    font-size: 16px;
}
Answer from Rostyk on Stack Overflow
🌐
Tailwind CSS
tailwindcss.com › docs › background-color
background-color - Backgrounds - Tailwind CSS
Use utilities like bg-white, bg-indigo-500 and bg-transparent to control the background color of an element:
🌐
Reddit
reddit.com › r/tailwindcss › tailwind bg color won't change
r/tailwindcss on Reddit: Tailwind bg color won't change
September 5, 2023 -

I'm trying to create a sidebar. I am using a template I found and am trying to change the color from indigo to cyan. When I try to change the code to be

bg-cyan-700

I get the grayed out photo whereas the indigo shows indigo background. How could this be happening? I inspected the element and it shows cyan but the front end doesn't reflect the change...

How could this be happening?

<aside
      className={classNames({
        // "bg-cyan-700 text-zinc-50 fixed md:static md:translate-x-0 z-20": true, // want to change to cyan

        // ORIGINAL COLOR
        "bg-indigo-700 text-zinc-50 fixed md:static md:translate-x-0 z-20":
          true,
        "transition-all duration-300 ease-in-out": true, // makes the transition really nice and smooth
        "w-[200px]": !collapsed,
        "w-16": collapsed,
        "-translate-x-full": !shown, //not super sure what this does
      })}
    >

🌐
Medium
medium.com › @python-javascript-php-html-css › fixing-background-color-issues-with-tailwind-and-react-1462ad06e9b4
Fixing Background Color Issues with Tailwind and React
August 24, 2024 - Ensuring that your configuration ... or excessive pruning of styles. ... This issue often results from conflicts with other stylesheets or incorrect Tailwind configuration files....
🌐
GitHub
github.com › tailwindlabs › discuss › issues › 367
Background color not changing · Issue #367 · tailwindlabs/discuss
October 28, 2019 - Hi, I am learning Tailwind CSS and I was trying to implement it on a project. The color is not loading even though I have specified the specific tags for it. I am attaching a screenshot showing the website and the Inspector. TIA for the ...
Published   Oct 28, 2019
🌐
Tailwind CSS
night-tailwindcss.vercel.app › docs › background-color
Background Color - Tailwind CSS
To control the background color of an element on focus, add the focus: prefix to any existing background color utility. For example, use focus:bg-blue-500 to apply the bg-blue-500 utility on focus.
Find elsewhere
🌐
InfinityFree
forum.infinityfree.com › hosting support
Tailwind CSS Background Not Appearing - Hosting Support - InfinityFree Forum
May 13, 2024 - Everything works the way it’s supposed to. The default light-mode doesn’t work. It works when I test it locally. I’ve followed all of the directions on how to use Tailwind CSS. No background colors appear when I’m not in Dark Mode. Even stranger, is how finicky the JavaS...
🌐
Codedamn
codedamn.com › news › frontend
How to fix color not working in Tailwind CSS?
November 26, 2023 - To use these utilities, simply add classes like text-blue-500 or bg-red-300 to your HTML elements. Remember to use Tailwind’s responsive prefixes and hover-state modifiers to add dynamic color changes.
Top answer
1 of 6
45

in Tailwind you can't use dynamic class naming like bg-${color}.

This because when Tailwind compiles its CSS, it looks up over all of your code and checks if a class name matches.

If you want dynamic name classes you should write all the class name.

But for your specific use case, I would not use the JIT of Tailwind and instead use the style attribute and dynamically change the backgroundColor value.

It will use less CSS and also give you less headache.

Finally, this is my suggestion

const colors = ['#7a5195', '#bc5090','#ef5675'];

export default function App() {
  const names = ['Tyler', "Charles", 'Vince']
  const labels = {};

  names.forEach((name, index) => {
    labels[name] = colors[index];
  });

  return (
    <>

    {
      names.map((name) => (
        <div style={{ backgroundColor: `${labels[name]}` }}>
          {name}
        </div>
      )
    }
      
    </>
  );
}
2 of 6
6

You can also add classes to your safelist in your tailwind config.

// tailwind.config.js

// Create an array for all of the colors you want to use
const colorClasses = [
  '#7a5195', 
  '#bc5090',
  '#ef5675'
];

module.exports = {
  purge: {
    content: ["./src/**/*.{js,jsx,ts,tsx}", "./public/index.html"],
    // Map over the labels and add them to the safelist
    safelist: [
      ...colorClasses.map((color) => `bg-${color}`)
    ],
  },
  darkMode: false, // or 'media' or 'class'
  variants: {
    extend: {},
  },
  plugins: [require("@tailwindcss/forms")],
}

This way you can use the colors that were included in the colorClasses array dynamically as they will not be purged.

Note: If you want to do bg-blue-500 for example, you'll need to include all of the color weights as part of the safelist (as well as add that color to the array).

...colorClasses.map((color) => `bg-${color}-500`)
🌐
Jumpstartrails
jumpstartrails.com › discussions › tailwind-custom-color-not-working
Tailwind custom color not working
I tried restarting the server and running npx tailwindcss -o tailwind.css but it made no difference. Any idea what I'm missing? Thanks ... Same issue. Adding myself to the thread for updates. ... You've also saved an HTML file with the class in it? It might just be getting purged. ... Ah yes, I think you are right. It's working now :). Thanks ... I am having a similar issue. The issue is that when I have custom helpers to make badges etc. the other colors won't work.
🌐
GeeksforGeeks
geeksforgeeks.org › css › how-to-solve-default-colors-not-working-issue-in-tailwind-css
How to Solve "Default Colors Not Working" Issue in Tailwind CSS ? - GeeksforGeeks
June 24, 2024 - To use extended colors in an older version of Tailwind CSS, you can configure your tailwind.config.js file. If you want to override existing colors, avoid using the extend keyword; instead, define your custom color palette. Note: If you want to override the colors which are there do not use the extend keyword then all colors will be overridden if you don’t have a set of completely custom colors in mind for your project, you can curate your colors from our default palette by importing tailwind CSS/colors in your configuration file and choosing the colors you want to use:
🌐
Tailwind
windframe.dev › tailwind › classes › tailwind-background-color
The Tailwind background color utility classes are used to add a background color to an element. Tailwind CSS provides a wide range of color options that you can use out of the box.
In the above example, the bg-red-400 ... the second <button> element, setting its background color to a darker shade of red. While Tailwind offers a comprehensive color palette, there might be instances where you need a specific color not included by default....
🌐
Tailkits
tailkits.com › blog
A Simple Guide to Background Colors in Tailwind CSS | Tailkits
January 1, 2025 - If your background color isn't showing up, check the following: Class Names: Make sure the class names are typed correctly. CSS Specificity: Inline styles or other CSS might be overriding your Tailwind classes.
🌐
Tailwind CSS
tailwind.build › classes › background-color › bg-black
.bg-black - Tailwind CSS class
.bg-black { background-color: #000; } .bg-transparent · .bg-current · .bg-white · .bg-gray-100 · .bg-gray-200 · .bg-gray-300 · .bg-gray-400 · .bg-gray-500 · .bg-gray-600 · .bg-gray-700 · .bg-gray-800 · .bg-gray-900 · .bg-red-100 · .bg-red-200 · .bg-red-300 ·