Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Flowbite components render but look unstyled in a Tailwind project

ErrorFlowbite buttons, cards or modals render with no colours, spacing or borders

Short answer

Flowbite React ships its classes inside node_modules, and Tailwind v4 does not scan node_modules by default, so those classes are never generated. Run the Flowbite React init command, or register the package folder with an @source line in your CSS. Also check that your stylesheet imports Tailwind and that class names are not built by string concatenation.

  • Applies to Tailwind CSS 4, flowbite-react, React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the browser dev tools, inspect a Flowbite button and look at its class list. If the classes are there but no CSS rule matches them, Tailwind never generated them: a source-scanning problem, not a markup problem.

    npm ls flowbite-react tailwindcss
    grep -rn "@import \"tailwindcss\"" src/
  2. 2Match what you see, then jump to its fix

    1. 1A fresh install: components render, nothing is styled.Flowbite React setup was never runFix
    2. 2Your own components style fine; only the library's components do not.Tailwind does not scan node_modules, where the component classes liveFix
    3. 3Components you wrap or extend lose some styles, for example bg-${color}-600.Class names in your own code are built from piecesFix

What does the error look like?

  • Flowbite buttons, cards or modals render with no colours, spacing or borders
  • Tailwind classes work in my own components but not in Flowbite components

Cause 1 of 3

Flowbite React setup was never run

1Check

The project README for flowbite-react says that adding it to an existing project is done with its init command, which sets up the dependencies and configuration it needs.

git status --short

2Fix

Run the init command in the project root, then restart the dev server.

npx flowbite-react@latest init

3Verify

Restart the dev server and reload; the components pick up their styles.

npm run dev

Confirmed by github.com

Did this fix it?

Cause 2 of 3

Tailwind does not scan node_modules, where the component classes live

1Check

Tailwind scans every file except .gitignore entries, node_modules, binary files, CSS files and lock files. A package built with Tailwind therefore has to be registered with @source.

grep -rn "@source" src/ *.css 2>/dev/null

2Fix

Add an @source line in your main CSS file, with the path relative to that stylesheet, pointing at the package folder. Adjust the path to where your stylesheet is.

/* src/index.css */
@import "tailwindcss";
@source "../node_modules/flowbite-react";

3Verify

Rebuild; the previously unstyled component gets its colours.

npm run build

Confirmed by tailwindcss.com

Did this fix it?

Cause 3 of 3

Class names in your own code are built from pieces

1Check

Tailwind reads source files as plain text and cannot follow string interpolation, so a class such as text-red-600 built from parts is never generated.

grep -rn "bg-\${\|text-\${" src/

2Fix

Write complete class names and choose between them.

const tone = error ? 'text-red-600' : 'text-green-600';

3Verify

The class appears in the generated CSS.

npm run build && grep -c "text-red-600" dist/assets/*.css

Confirmed by tailwindcss.com

Did this fix it?

How do I stop it coming back?

  • Follow the framework guide for Vite, Next.js or Astro linked from the flowbite-react repository, instead of copying a Tailwind config from an older project.
  • After installing any UI kit built on Tailwind, check whether it needs an @source line.
  • Use full class names in code so Tailwind can find them.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

Tailwind is installed but the utility classes do nothing

Tailwind classes work in some components but not in others

When classes have no effect, the stylesheet either lacks the v4 import line, is never loaded by the page, or the class name never appears as plain text in a scanned file.

5 causes, each with a fix

Web apps

Hydration failed after adding next-themes dark mode

Console reports a server and client mismatch on the html element

next-themes changes the html element and knows the theme only in the browser, so server HTML and client HTML differ.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.