diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5a5742b7eb40..737c3034bcee 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Vite: Don't crash when importing a virtual module in JavaScript that ends in `.css` ([#16780](https://github.com/tailwindlabs/tailwindcss/pull/16780))
+- Ensure `@reference "…"` does not emit CSS variables ([#16774](https://github.com/tailwindlabs/tailwindcss/pull/16774))
+- Fix an issue where `@reference "…"` would sometimes omit keyframe animations ([#16774](https://github.com/tailwindlabs/tailwindcss/pull/16774))
## [4.0.8] - 2025-02-21
diff --git a/integrations/cli/index.test.ts b/integrations/cli/index.test.ts
index 2eee0413dc4f..bc8fb433ddf2 100644
--- a/integrations/cli/index.test.ts
+++ b/integrations/cli/index.test.ts
@@ -643,7 +643,7 @@ test(
}
`,
'index.css': css`
- @import 'tailwindcss/theme' theme(reference);
+ @reference 'tailwindcss/theme';
/* (1) */
/* - Only './src' should be auto-scanned, not the current working directory */
@@ -774,7 +774,7 @@ test(
}
`,
'project-a/src/index.css': css`
- @import 'tailwindcss/theme' theme(reference);
+ @reference 'tailwindcss/theme';
/* Run auto-content detection in ../../project-b */
@import 'tailwindcss/utilities' source('../../project-b');
@@ -1132,7 +1132,7 @@ test(
}
`,
'index.css': css`
- @import 'tailwindcss/theme' theme(reference);
+ @reference 'tailwindcss/theme';
/* (1) */
/* - Only './src' should be auto-scanned, not the current working directory */
diff --git a/integrations/cli/standalone.test.ts b/integrations/cli/standalone.test.ts
index a40d69fc95b7..c190134d307b 100644
--- a/integrations/cli/standalone.test.ts
+++ b/integrations/cli/standalone.test.ts
@@ -35,7 +35,7 @@ test(
`,
'src/index.css': css`
- @import 'tailwindcss/theme' theme(reference);
+ @reference 'tailwindcss/theme';
@import 'tailwindcss/utilities';
@plugin '@tailwindcss/forms';
diff --git a/integrations/postcss/index.test.ts b/integrations/postcss/index.test.ts
index 1c8d1c301716..524752b217f7 100644
--- a/integrations/postcss/index.test.ts
+++ b/integrations/postcss/index.test.ts
@@ -659,7 +659,7 @@ test(
}
`,
'index.css': css`
- @import 'tailwindcss/theme' theme(reference);
+ @reference 'tailwindcss/theme';
/* (1) */
/* - Only './src' should be auto-scanned, not the current working directory */
@@ -799,7 +799,7 @@ test(
}
`,
'project-a/src/index.css': css`
- @import 'tailwindcss/theme' theme(reference);
+ @reference 'tailwindcss/theme';
/* Run auto-content detection in ../../project-b */
@import 'tailwindcss/utilities' source('../../project-b');
@@ -1163,7 +1163,7 @@ test(
}
`,
'index.css': css`
- @import 'tailwindcss/theme' theme(reference);
+ @reference 'tailwindcss/theme';
/* (1) */
/* - Only './src' should be auto-scanned, not the current working directory */
diff --git a/integrations/postcss/multi-root.test.ts b/integrations/postcss/multi-root.test.ts
index 327becdfef99..c2c52c7e4dbd 100644
--- a/integrations/postcss/multi-root.test.ts
+++ b/integrations/postcss/multi-root.test.ts
@@ -25,7 +25,7 @@ test(
`,
'src/shared.css': css`
- @import 'tailwindcss/theme' theme(reference);
+ @reference 'tailwindcss/theme';
@import 'tailwindcss/utilities';
`,
'src/root1.css': css`
diff --git a/integrations/postcss/next.test.ts b/integrations/postcss/next.test.ts
index 48c6a18dfcc0..a6fb26f8e6ad 100644
--- a/integrations/postcss/next.test.ts
+++ b/integrations/postcss/next.test.ts
@@ -19,21 +19,13 @@ test(
}
`,
'postcss.config.mjs': js`
- /** @type {import('postcss-load-config').Config} */
- const config = {
+ export default {
plugins: {
'@tailwindcss/postcss': {},
},
}
-
- export default config
- `,
- 'next.config.mjs': js`
- /** @type {import('next').NextConfig} */
- const nextConfig = {}
-
- export default nextConfig
`,
+ 'next.config.mjs': js`export default {}`,
'app/layout.js': js`
import './globals.css'
@@ -46,12 +38,21 @@ test(
}
`,
'app/page.js': js`
+ import styles from './page.module.css'
export default function Page() {
- return Hello, Next.js!
+ return (
+ Hello, Next.js!
+ )
+ }
+ `,
+ 'app/page.module.css': css`
+ @reference './globals.css';
+ .heading {
+ @apply text-red-500 animate-ping;
}
`,
'app/globals.css': css`
- @import 'tailwindcss/theme' theme(reference);
+ @reference 'tailwindcss/theme';
@import 'tailwindcss/utilities';
`,
},
@@ -60,14 +61,26 @@ test(
await exec('pnpm next build')
let files = await fs.glob('.next/static/css/**/*.css')
- expect(files).toHaveLength(1)
- let [filename] = files[0]
+ expect(files).toHaveLength(2)
- await fs.expectFileToContain(filename, [
+ let globalCss: string | null = null
+ let moduleCss: string | null = null
+ for (let [filename, content] of files) {
+ if (content.includes('@keyframes page_ping')) moduleCss = filename
+ else globalCss = filename
+ }
+
+ await fs.expectFileToContain(globalCss!, [
candidate`underline`,
candidate`font-bold`,
candidate`text-3xl`,
])
+
+ await fs.expectFileToContain(moduleCss!, [
+ 'color:var(--color-red-500,oklch(.637 .237 25.331)',
+ 'animation:var(--animate-ping,ping 1s cubic-bezier(0,0,.2,1) infinite)',
+ /@keyframes page_ping.*{75%,to{transform:scale\(2\);opacity:0}/,
+ ])
},
)
@@ -90,21 +103,13 @@ describe.each(['turbo', 'webpack'])('%s', (bundler) => {
}
`,
'postcss.config.mjs': js`
- /** @type {import('postcss-load-config').Config} */
- const config = {
+ export default {
plugins: {
'@tailwindcss/postcss': {},
},
}
-
- export default config
- `,
- 'next.config.mjs': js`
- /** @type {import('next').NextConfig} */
- const nextConfig = {}
-
- export default nextConfig
`,
+ 'next.config.mjs': js`export default {}`,
'app/layout.js': js`
import './globals.css'
@@ -117,12 +122,19 @@ describe.each(['turbo', 'webpack'])('%s', (bundler) => {
}
`,
'app/page.js': js`
+ import styles from './page.module.css'
export default function Page() {
- return Hello, Next.js!
+ return Hello, Next.js!
+ }
+ `,
+ 'app/page.module.css': css`
+ @reference './globals.css';
+ .heading {
+ @apply text-red-500 animate-ping content-['module'];
}
`,
'app/globals.css': css`
- @import 'tailwindcss/theme' theme(reference);
+ @reference 'tailwindcss/theme';
@import 'tailwindcss/utilities';
`,
},
@@ -142,13 +154,16 @@ describe.each(['turbo', 'webpack'])('%s', (bundler) => {
await retryAssertion(async () => {
let css = await fetchStyles(url)
expect(css).toContain(candidate`underline`)
+ expect(css).toContain('content: var(--tw-content)')
+ expect(css).toContain('@keyframes')
})
await fs.write(
'app/page.js',
js`
+ import styles from './page.module.css'
export default function Page() {
- return Hello, Next.js!
+ return Hello, Next.js!
}
`,
)
@@ -157,7 +172,9 @@ describe.each(['turbo', 'webpack'])('%s', (bundler) => {
await retryAssertion(async () => {
let css = await fetchStyles(url)
expect(css).toContain(candidate`underline`)
- expect(css).toContain(candidate`text-red-500`)
+ expect(css).toContain(candidate`bg-red-500`)
+ expect(css).toContain('content: var(--tw-content)')
+ expect(css).toContain('@keyframes')
})
},
)
@@ -181,21 +198,13 @@ test(
}
`,
'postcss.config.mjs': js`
- /** @type {import('postcss-load-config').Config} */
- const config = {
+ export default {
plugins: {
'@tailwindcss/postcss': {},
},
}
-
- export default config
- `,
- 'next.config.mjs': js`
- /** @type {import('next').NextConfig} */
- const nextConfig = {}
-
- export default nextConfig
`,
+ 'next.config.mjs': js`export default {}`,
'app/a/[slug]/page.js': js`
export default function Page() {
return Hello, Next.js!
diff --git a/integrations/postcss/plugins.test.ts b/integrations/postcss/plugins.test.ts
index 3081b7bfee9f..c36e8fd14edd 100644
--- a/integrations/postcss/plugins.test.ts
+++ b/integrations/postcss/plugins.test.ts
@@ -26,7 +26,7 @@ test(
`,
'src/index.css': css`
- @import 'tailwindcss/theme' theme(reference);
+ @reference 'tailwindcss/theme';
@import 'tailwindcss/utilities';
@plugin '@headlessui/tailwindcss';
`,
@@ -65,7 +65,7 @@ test(
`,
'src/index.css': css`
- @import 'tailwindcss/theme' theme(reference);
+ @reference 'tailwindcss/theme';
@import 'tailwindcss/utilities';
@plugin '@headlessui/tailwindcss';
`,
diff --git a/integrations/vite/index.test.ts b/integrations/vite/index.test.ts
index afc58c558bf5..59b304cf4079 100644
--- a/integrations/vite/index.test.ts
+++ b/integrations/vite/index.test.ts
@@ -62,7 +62,7 @@ describe.each(['postcss', 'lightningcss'])('%s', (transformer) => {
}
`,
'project-a/src/index.css': css`
- @import 'tailwindcss/theme' theme(reference);
+ @reference 'tailwindcss/theme';
@import 'tailwindcss/utilities';
@config '../tailwind.config.js';
@source '../../project-b/src/**/*.html';
@@ -147,7 +147,7 @@ describe.each(['postcss', 'lightningcss'])('%s', (transformer) => {
}
`,
'project-a/src/index.css': css`
- @import 'tailwindcss/theme' theme(reference);
+ @reference 'tailwindcss/theme';
@import 'tailwindcss/utilities';
@config '../tailwind.config.js';
@source '../../project-b/src/**/*.html';
@@ -291,7 +291,7 @@ describe.each(['postcss', 'lightningcss'])('%s', (transformer) => {
}
`,
'project-a/src/index.css': css`
- @import 'tailwindcss/theme' theme(reference);
+ @reference 'tailwindcss/theme';
@import 'tailwindcss/utilities';
@import './custom-theme.css';
@config '../tailwind.config.js';
diff --git a/integrations/vite/multi-root.test.ts b/integrations/vite/multi-root.test.ts
index b407f7da0bc4..d1a1337a4f5d 100644
--- a/integrations/vite/multi-root.test.ts
+++ b/integrations/vite/multi-root.test.ts
@@ -43,7 +43,7 @@ test(