Installing Tailwind CSS v4 in a Blazor v9 WebApp

I had a horrible experience with Tailwind, up until some YouTube contributors (listed at the bottom of this post) had up to date videos on the matter. Certainly, AI is still trailing on up to the second content.

I'm using Windows 11 and Rider and a Blazor WebApp with InteractiveAuto specified, so I have two projects.

  1. Download the stand alone executable for tailwindcss cli. You can find that here. Ignore the documentation, it's out of date and still talking about tailwind.config.js. 🤦
  2. Put the executable in your path so you don't have to go digging later.
  3. Also, rename it something shorter so you can type less - I called minetw4cli.
💡
Lots of places in the TailwindCSS documentation says that you won't need node.js if you're using the cli.
1. But if you don't have tailwind installed, the @import "tailwindcss"; directive doesn't work.
2. The only way I can figure out to install it is with node.
3. I stopped fighting it.
💡
All of the following are done in the root of the server project and not the client project.
  1. Install Tailwind. Some instructions will tell you to install the cli at the same time. But that's the one that runs under npm and not the one you downloaded. Here's the short version that only installs TailwindCss:
npm install tailwindcss
  1. Following Chris Sainty's excellent material (don't follow the installation instructions, they're for v3) do the following:
    1. Create a Styles folder in the server project.
    2. Create an input.css file in that folder
    3. Add one line to the input.css file (you might add more later)
@import "tailwindcss";
  1. And in what would be a giant "up-yours" to all people trying to get actual work done, this file has to have an encoding of UTF-8. If you created in via the context menu in Rider, it won't. And then the command will fail with:
Error: Invalid declaration: `@import "tailwindcss"`

If you're in Rider select the input.css file, then use the menu File=>File Encoding and set it.

  1. Open a terminal window in the Solution root folder, not the server or client project folders, and enter the following command:
tw4cli -i ./<server-project-name>/styles/input.css -o ./<server-project-name>/wwwroot/app.css --watch

Because we are now in the root of the solution, the cli will scan all child folders. I could not find this documented anywhere, but with v4 you don't specify a config to locate your source, therefor it must scan everything underneath the current folder.

This is how it can pick up classes you've used in both projects and ensure that the final app.css includes them all.

  1. Update your server launchSettings.json file to include the lines below for hotReload. Remember to update both http and https profiles:
"hotReloadEnabled": true,
"watchStaticFiles": true,

If you are running dotnet watch in a terminal in the server project root directory, then as you make changes to the client or server projects, the cli will pick up those changes, add them to app.css and dotnet watch will rebuild and you will see the changes right away.

I still can't get IntelliSense working, but other than that, it seems to be functioning.

YouTube videos that helped:

Jolly Coding
Hi, I’m James. I’m a developer advocate passionate about all things web development, especially TypeScript and React. This channel is a spot for tutorials, tips, and insights on the latest web technologies.
Lukas | Web Development & Design
Hi! I’m Luke, a self-taught Web Developer from Austria. On this channel, I share videos about HTML, CSS, Tailwind CSS, JavaScript, ReactJS, Git, GitHub and many more. Content that’s designed to help you become successful as a Frontend Developer, Web Developer or Full Stack Developer. SUBSCRIBE to the channel and become a part of this journey. 🔥🚀 Milestones: 50 Subscribers: 27.05.2023 2.500 Views: 31.05.2023 100 Subscribers: 01.06.2023 5.000 Views: 05.06.2023 10.000 Views: 10.06.2023 500 Subscribers: 11.06.2023 25.000 Views: 13.06.2023 1.000 Subscribers: 13.06.2023 50.000 Views: 17.06.2023 2.500 Subscribers: 19.06.2023 4.000 Watch hours: 21.06.2023 100.000 Views: 05.07.2023 5.000 Subscribers: 23.07.2023 250.000 Views: 28.09.2023 10.000 Subscribers: 26.10.2023 500.000 Views: 01.05.2024 15.000 Subscribers: 12.07.2024 700.000 Views: 26.12.2024 20.000 Subscribers: 02.06.2025 1.000.000 Views: 14.07.2025