9

I used this setup guide for setting TailwindCSS with my Angular application. However there is no tailwind.config.js. I tried a lot of online blogs but didn't work. How can I setup tailwind.config.js and customize the behavior. Is there a another way to customize tailwind with Angular.

I even added tailwind.config.js manually but when I use those configuration, it didn't work. These are the version I m using.

  • Angular v19.1
  • TailwindCSS v4.0

TailwindCSS is working in my application but Is there a way to configure with tailwind.config.js.

3
  • sorry ,but where is the problem , what is working and not working I don't get your point if the setup guid was working for you ?? Commented Feb 19 at 15:07
  • 1
    I want to customise styles like defining my own colors or spaces. When I was using vite and react , i would get tailwind.config.js and I used to define. Now using this setup , I am not able to customize coz no tailwind config file Commented Feb 20 at 5:24
  • 1
    @MuhammedAlbarmavi It works, but the question is whether it could be configured with a tailwind.config.js file, as it is currently using v4 without one. They manually created the config file, but from v4 onward, this is irrelevant. Starting with v4, they are moving away from JS-based configuration, so even though they created the file and added content to it, v4 did not take it into account. However, there is still a way to force JS-based configuration using the @config directive. Commented Feb 20 at 12:56

1 Answer 1

10

TL;DR: Use @config directive.

From v4 onwards, the use of the tailwind.config.js file has been removed, and CSS-first directives are provided for configuration. The init process, which previously generated this config file by default, has also been discontinued. If you want to use a JS-based config file from v4 onwards, you must create it manually and specify its location in CSS using the @config directive so that v4 can find the configuration.

TailwindCSS v4 is backwards compatible with v3

I see that you've created the old v3 legacy JavaScript-based configuration. In v4, this is no longer necessary due to the new CSS-first configuration, but you can still use it by adding an extra @config directive if needed.

Using a JavaScript config file

JavaScript config files are still supported for backward compatibility, but they are no longer detected automatically in v4.

If you still need to use a JavaScript config file, you can load it explicitly using the @config directive:

@config "../../tailwind.config.js";

The configuration setting has changed by default. However, you have the option to declare the location of your tailwind.config.js file using a relative path in your default CSS file so you can use it again.

New configuration option in v4

CSS-First Configuration: Customize and extend the framework directly in CSS instead of JavaScript.

With TailwindCSS v4, you have the option to omit the tailwind.config.js file. You can find many new directives, such as @theme, which allows you to declare your custom settings directly in your CSS file, or @plugin, which lets you import TailwindCSS v4-compatible plugins directly in your CSS file.

I won't list all the new directives, but you can check them out here:

Sign up to request clarification or add additional context in comments.

1 Comment

Is it considered bad practice to use config and directive, ie @config "../../tailwind.config.js"; to extend tailwind? For example, I want to add a max-w-9xl: 96rem to the config file, pipe it in with the @config directive, then in globals.cssbe able to override it @theme { --max-w-9xl: 92rem; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.