Tailwind v4 has no important
option support
#15866
-
I tried updating tailwind to v4 today, but I noticed there is no support for the In my case, I have a chrome extension which injects dom onto some pages. I use the important cause like this |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
You'd replace the @layer theme, base, components, utilities;
@import "tailwindcss/theme.css" layer(theme);
@import "tailwindcss/preflight.css" layer(base);
@theme {
/* ... */
}
@layer utilities {
#my-extension {
@tailwind utilities;
}
} |
Beta Was this translation helpful? Give feedback.
-
After several attempts, I discovered that using the .app {
@import 'tailwindcss' source('../src');
} Compiled result: @layer theme, base, components, utilities;
@layer theme {
.app :root, .app :host {
--font-sans: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji",
"Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
...
}
}
@layer base {
.app *, .app ::after, .app ::before, .app ::backdrop, .app ::file-selector-button {
box-sizing: border-box;
...
}
.app html, .app :host {
line-height: 1.5;
-webkit-text-size-adjust: 100%;
...
}
...
}
@layer utilities {
.app .text-red-500 {
color: var(--color-red-500);
}
...
} Soon, I realized that selectors like In the end, I didn’t need to modify the My configuration: /* input.css */
@import 'tailwindcss' source('../src'); /* postcss.config.mjs */
export default {
plugins: {
'@tailwindcss/postcss': {},
'postcss-nested': {},
'postcss-prefix-selector': { prefix: '.app' },
},
} The If you don't need to transform CSS Nesting syntax for legacy browser compatibility, you can remove the 'postcss-prefix-selector': {
prefix: '.app',
transform: (prefix, selector, prefixedSelector, filePath, rule) => {
// Skip nested rules — only apply prefix to root-level rules
if (rule.parent && rule.parent.type === 'rule') {
return selector;
}
// Apply prefix to top-level selector only
return prefixedSelector;
},
}, Compiled result: .app .a {
.b {
...
}
} |
Beta Was this translation helpful? Give feedback.
You'd replace the
@import "tailwindcss";
with: