Skip to content

[v4] Tailwind generates a lot of unused styles #16571

@filipsobol

Description

@filipsobol

Steps to reproduce

  1. Create a fresh Vite project.
  2. Add Tailwind following the Installation guide.
  3. Add @import "tailwindcss";.
  4. Do not use any Tailwind classes in the code.
  5. Run the npm run build command.

Expected result

The generated CSS file should contain only essential styles, such as CSS resets, with a file size of approximately 2 KB.

Actual result

The generated CSS file includes a significant number of unused styles, with a total size of 21.8 KB.

  • ~360 CSS variables,
  • utilities styles,
  • @keyframes rules,
  • @property rules.

Workaround

PurgeCSS can remove most of the unused styles, except for @property rules:

// postcss.config.js

import { purgeCSSPlugin } from '@fullhuman/postcss-purgecss';

export default {
  plugins: [
    purgeCSSPlugin( {
      content: [
        './index.html',
        './src/**/*'
      ],
      fontFace: true,
      keyframes: true,
      variables: true
    } )
  ]
}

With this configuration, the final CSS file size is reduced to approximately 4 KB.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions