Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v4] Tailwind bundles unused css variables, bloating up the css #16145

Open
GiyoMoon opened this issue Feb 1, 2025 · 1 comment
Open

[v4] Tailwind bundles unused css variables, bloating up the css #16145

GiyoMoon opened this issue Feb 1, 2025 · 1 comment

Comments

@GiyoMoon
Copy link

GiyoMoon commented Feb 1, 2025

What version of Tailwind CSS are you using?

v4.0.2

What build tool (or framework if it abstracts the build tool) are you using?

Playground

What version of Node.js are you using?

Playground version

What browser are you using?

Chromium

What operating system are you using?

macOS

Reproduction URL

https://play.tailwindcss.com/

Delete the entire html file, switch between v4 and v3 and compare the size of the generated css file.

Describe your issue

Tailwind v4.0 ships all css variables of the default theme, even if they aren't being used. This bloats up the css by a good amount. Default sizes with no classes used in the html:

  • v3 - 1.16kb
  • v4 - 4.01kb
    The size increased by 345%. Is there a way to strip of unused variables without having to "reset" the default theme and define it manually as described in here?
@GiyoMoon GiyoMoon changed the title Tailwind v4.0 bundles unused css variables, bloating up the css [v4] Tailwind bundles unused css variables, bloating up the css Feb 1, 2025
@Pilaton
Copy link

Pilaton commented Feb 2, 2025

Yes, the optimization of the assembly in version 4 is not at all pleasing.
The CSS code has become much more weighty.

You can compare these two example styles for font-weight from the final bundle:

v3

.font-bold {
  font-weight: 700
}
.font-extrabold {
  font-weight: 800
}
.font-light {
  font-weight: 300
}
.font-medium {
  font-weight: 500
}
.font-normal {
  font-weight: 400
}
.font-semibold {
  font-weight: 600
}

v4

@layer theme {
  :host,:root {
    --font-weight-bold: 700;
    --font-weight-extrabold: 800;
    --font-weight-light: 300;
    --font-weight-medium: 500;
    --font-weight-normal: 400;
    --font-weight-semibold: 600;
  }
}

.font-bold {
  --tw-font-weight: var(--font-weight-bold);
  font-weight: var(--font-weight-bold)
}
.font-extrabold {
  --tw-font-weight: var(--font-weight-extrabold);
  font-weight: var(--font-weight-extrabold)
}
.font-light {
  --tw-font-weight: var(--font-weight-light);
  font-weight: var(--font-weight-light)
}
.font-medium {
  --tw-font-weight: var(--font-weight-medium);
  font-weight: var(--font-weight-medium)
}
.font-normal {
  --tw-font-weight: var(--font-weight-normal);
  font-weight: var(--font-weight-normal)
}
.font-semibold {
  --tw-font-weight: var(--font-weight-semibold);
  font-weight: var(--font-weight-semibold)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants