Skip to content

Migrating an Angular project (with Sass) to Tailwind CSS v4

The Tailwind CSS v4 release is a big one, with a lot of changes. Unfortunately, the automated upgrade tool doesn’t work with Sass (i.e. .scss files). If you have an Angular project with Sass (e.g. one that uses Angular Material) you can’t directly use the upgrade tool.

In this post, I show you how to manually migrate an Angular project with Sass to Tailwind v4, whilst still using the automated upgrade tool to do most of the work.

When you run npx @tailwindcss/upgrade@next — the upgrade tool — in your Angular (with Sass) project you’ll see output like the following:

Terminal window
tailwindcss v4.0.2
Searching for CSS files in the current directory and its subdirectories…
Cannot find any CSS files that reference Tailwind CSS.
Before your project can be upgraded you need to create a CSS file that imports Tailwind
CSS or uses `@tailwind`.
No PostCSS config found, skipping migration.
Updating dependencies…
Updated package: `tailwindcss`
Verify the changes and commit them to your repository.

You can see here that the upgrade tool can’t find any CSS files that reference Tailwind CSS, as we’re using Sass (.scss). It also doesn’t detect a PostCSS config, as the Angular CLI took care of this for you for Tailwind v3.

To “force” the upgrade tool to work we’ll:

  1. Create a PostCSS config file in the root — we’ll need this anyway for Tailwind v4 so it’ll stay.
  2. We’ll create a temporary CSS file in the root that contains only the Tailwind specific bits from our src/styles.scss file. This is only temporary and for the upgrade tool to do its magic. We’ll inspect the changes made and apply them to our main styles file and delete this temporary one.
  1. Make sure you start with a clean working directory and commit any changes you have, as we’ll be using git diff to see what changes the upgrade tool makes — so we know what changes to apply manually to our src/styles.scss file, and how templates etc. have been updated.

  2. Create a .postcssrc.json file in the root of your project with the following:

    {
    "plugins": {
    "tailwindcss": {},
    "autoprefixer": {}
    }
    }
  3. Create a tailwind.tmp.css file in the root of your project and copy over only the Tailwind specific bits from your main src/styles.scss file. For example:

    @import 'tailwindcss/base';
    @import 'tailwindcss/components';
    @import 'tailwindcss/utilities';
  4. Run the upgrade tool:

    Terminal window
    npx @tailwindcss/upgrade@next --force

    You should see output like:

    Terminal window
    tailwindcss v4.0.2
    Searching for CSS files in the current directory and its subdirectories…
    Linked `./tailwind.config.js` to `./tailwind.tmp.css`
    Migrating JavaScript configuration files…
    Migrated configuration file: `./tailwind.config.js`
    Migrating templates…
    Migrated templates for configuration file: `./tailwind.config.js`
    Migrating stylesheets…
    Migrated stylesheet: `./tailwind.tmp.css`
    Installed package: `@tailwindcss/postcss`
    Removed package: `autoprefixer`
    Updating dependencies…
    Updated package: `tailwindcss`
    Verify the changes and commit them to your repository.
  5. Inspect your tailwind.tmp.css file and compare it to your src/styles.scss file.

    You can use git diff to see the changes made by the upgrade tool:

    Terminal window
    git diff tailwind.tmp.css

    You’ll need to apply these changes to your main src/styles.scss file manually to complete this migration.

  6. Inspect any changes the upgrade tool may have made to template files, and run ng serve to test that your app is working as expected.

  7. Once you’re happy with the changes, you can delete the tailwind.tmp.css file and commit your changes 🚀