---
title: Using Tailwind CSS with Angular
description: Learn how to set up and configure Tailwind CSS in Angular applications and libraries within an Nx workspace, including dependency management and Module Federation support.
sidebar:
  label: Using Tailwind CSS with Angular
filter: 'type:Guides'
topics:
  - 'Angular'
---

This guide shows how to set up and configure [Tailwind CSS](https://tailwindcss.com/) with [Angular](https://angular.dev/) projects in an Nx workspace.

## Installation

For the most up-to-date installation instructions, refer to the official Tailwind CSS documentation:

- **Angular projects**: [Tailwind CSS with Angular](https://tailwindcss.com/docs/installation/framework-guides/angular)
- **Other setups**: [Tailwind CSS installation guide](https://tailwindcss.com/docs/installation)

## Configuring sources for monorepos

### Tailwind CSS v4

Tailwind CSS v4 [automatically detects classes from source files](https://tailwindcss.com/docs/detecting-classes-in-source-files). However, with Angular PostCSS plugin, scanning starts from the workspace root by default. This means classes from all libraries end up in your production CSS, even unused ones.

To avoid bloated CSS, restrict scanning to your app folder and explicitly add your library dependencies:

```css
// apps/myapp/src/styles.css
@import "tailwindcss" source("./app");

@source "../../../libs/ui";
@source "../../../libs/shared";
```

#### Automating @source directives

Manually maintaining `@source` directives is tedious and error-prone. Use [`@juristr/nx-tailwind-sync`](https://www.npmjs.com/package/@juristr/nx-tailwind-sync) to automate this based on your project's dependency graph.

Install the package:

```shell
npm install @juristr/nx-tailwind-sync
```

Register the sync generator for your application's `build` and `serve` targets:

{% tabs syncKey="project-config-file" %}
{% tabitem label="project.json" %}

```json
{
  "name": "myapp",
  "targets": {
    "build": {
      "executor": "@angular/build:application",
      "syncGenerators": ["@juristr/nx-tailwind-sync:source-directives"]
    },
    "serve": {
      "executor": "@angular/build:dev-server",
      "syncGenerators": ["@juristr/nx-tailwind-sync:source-directives"]
    }
  }
}
```

{% /tabitem %}
{% tabitem label="package.json" %}

```json
{
  "name": "myapp",
  "nx": {
    "targets": {
      "build": {
        "syncGenerators": ["@juristr/nx-tailwind-sync:source-directives"]
      },
      "serve": {
        "syncGenerators": ["@juristr/nx-tailwind-sync:source-directives"]
      }
    }
  }
}
```

{% /tabitem %}
{% /tabs %}

When you run `nx build myapp` or `nx serve myapp`, the sync generator analyzes your dependency graph and updates your `styles.css` with the correct `@source` directives automatically.

For more details on why this is necessary and how Tailwind's scanning behavior differs between PostCSS and Vite, see [Tailwind v4 with Angular in an Nx Monorepo](/blog/setup-tailwind-4-angular-nx-workspace).

### Tailwind CSS v3

For Tailwind CSS v3, the [`content`](https://v3.tailwindcss.com/docs/content-configuration) property should be configured to include glob patterns that cover your project and its dependencies:

```javascript
// apps/my-app/tailwind.config.js
const { join } = require('path');

module.exports = {
  content: [
    join(__dirname, 'src/**/*.{ts,html}'),
    join(__dirname, '../../libs/**/*.{ts,html}'),
  ],
  theme: {
    extend: {},
  },
  plugins: [],
};
```

You can adjust the glob patterns based on your workspace structure. For example, you can be more selective by targeting individual libraries such as `libs/my-lib` rather than all libraries (`libs`). To learn how to automatically sync library dependencies with Tailwind sources, watch our video [Never Update Tailwind Glob Patterns Manually Again](https://www.youtube.com/watch?v=huTmV-F8c0A).
