You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This may be belong in the Infima repo, but I strongly suggest Docusaurus consider Tailwind. Tailwind already solves for theming out of the box. It also gives developers much more freedom. You can still re-implement Infima's core classes with tailwind, so this actually wouldn't need to be a breaking change.
Reacted by Fanny, Peter W, Anshul Goyal, Kash Sajadi, Jean-Philippe BOURGEON, Aman Mavai, David Bourgeois, Alistair Scott, HonkingGoose, Sébastien Lorber and 153 more
Reacted by Marko Kosir, Haku, Axel Emiliano León Rico and Joost De Cock
Reacted by Giampaolo Bellavite, Lucio D'Alessandro, James Singleton, Wasiq Bhamla, nino, Webber Takken, Erko Bridee, haobinliang-capitalise, Paddy Keane, Youness Id bakkasse and 17 more
Currently Infima is a css lib with a few postcss. But it also includes some lightweight vanilla JS components
If I understand correctly, you mean we could implement current Infima CSS classes as a Tailwind preset, instead of the existing css/postcss ?
So we would publish that preset and enable users to extend / customize it more easily?
I see the value of Tailwind, and a similar goal of styling co-located to the markup.
Its scope is larger than current Infima:
People having complex D2 sites will probably need additional one-of CSS styles that's not provided by Infima (afaik it also happens to Tailwind users). Atomic/utility CSS will grow slower than hand-made CSS.
There are also simple D2 sites that do not require additional styles. Can we use Tailwind without adding unnecessary CSS to these sites?
with package.json referencing a local module dependency "my-loaders": "file:plugins/my-loaders", and docusaurus.config.js plugins entry set up as plugins: ['my-loaders'],
And a tailwind.config.js like so:
module.exports={purge: ['./src/**/*.html','./src/**/*.js','./src/**/*.tsx'],darkMode: false,// or 'media' or 'class'theme: {extend: {},},variants: {extend: {},},plugins: [],}
Note that the PostCSS version in which Docusaurus v2 currently uses is 7.0.XX, while the latest version of PostCSS is 8.0.X and TailwindCSS v2 by default uses PostCSS V8. I had to use a v7 compatibility install of TailwindCSS v2 for this to all work: "tailwindcss": "npm:@tailwindcss/postcss7-compat" in package.json dependencies.
EDIT: With the newer versions of Docusaurus v2 supporting a configurePostCss option in a plugin, the above code snippet should be changed to the following:
@kvnxiao's solution is great! I just want to add an improvement to it. If you add the following to your tailwind.config.js: important: '#tailwind', then it will not affect the docusaurus pages. Then all you need to do is add <div id="tailwind"> around the pages that you want to use tailwind on!
Reacted by Florian Körner, Claire Froelich, Sébastien Lorber and David Boyne
@kvnxiao's (revised/edited) recipe in #2961 (comment) works quite well (better to snoop around in the Discord4J project they linked IMO to see how everything is laid out), with the addition that @tailwind entries need to be added to one's custom.css file, e.g.
This is standard fare for a tailwind project ofc, but I neglected to do this at first (I guess I thought postcss would somehow roll things up without those rules), and so thought the tailwind+docusaurus integration wasn't working for a while.
Tailwind 4 would be a great variant or even replacement for utility first approach. Having it as an option would be a killer. Infima is good but feels underweight for the range of use-cases Docusaurus has seen use for. Some well-positioned framework should work just fine and ensure so needed extensibility.
So desparate for an official Tailwind theme. Infima overrides everything. I can't even do something as simple as expressing m-0 for resetting an <h1> to zero margin, because Infima's invasive styles are on a higher-priority layer than Tailwind. The only way to outprioritise Infima is to use inline styles, which means just throwing away Tailwind.
So desparate for an official Tailwind theme. Infima overrides everything. I can't even do something as simple as expressing m-0 for resetting an <h1> to zero margin, because Infima's invasive styles are on a higher-priority layer than Tailwind. The only way to outprioritise Infima is to use inline styles, which means just throwing away Tailwind.
Creating a new Tailwind theme and overriding Infima things are 2 separate problems.
If Infima default/global styles are annoying, the issue to track is #6032
We may find a CSS solution that doesn't require introducing Tailwind. Creating a Tailwind theme remains a goal, but people who don't want Tailwind should also be able to customize things without being annoyed by Infima.
So desparate for an official Tailwind theme. Infima overrides everything. I can't even do something as simple as expressing m-0 for resetting an <h1> to zero margin, because Infima's invasive styles are on a higher-priority layer than Tailwind. The only way to outprioritise Infima is to use inline styles, which means just throwing away Tailwind.
set important to true and disable tailwind preflight
Had a quick look. Seems to work fine, without any warnings.
There's a couple of postcss related plugins configured in docusaurus webpack that need to be skipped in favour of using the new plugin (including lightning CSS, which is the core engine for Tailwind 4).
Docusaurus doesn't offer a hook to swap out those plugins, so a small custom plugin is required.
The approach I used is to use configureWebpack() (instead of the current configurePostCss()) to walk the webpack rules and replace postcss-loader with @tailwindcss/webpack.
Details
Replace the PostCSS-based Tailwind integration with the new dedicated webpack loader, eliminating PostCSS as a middleman.
src/plugins/tailwind-config.cjs — replace configurePostCss() with configureWebpack()
/** * Docusaurus plugin that replaces postcss-loader with @tailwindcss/webpack * in the CSS loader chain. The webpack loader handles Tailwind compilation * directly (via the Rust-based Oxide scanner) and uses Lightning CSS for * optimisation, eliminating the need for PostCSS, postcss-import, and autoprefixer. * * Non-Tailwind CSS files pass through unchanged (the loader bails out early * when no Tailwind directives are detected). */functiontailwindPlugin(){return{name: 'tailwind-plugin',configureWebpack(config){replacePostcssLoader(config.module?.rules)return{}},}}/** Recursively walk webpack rules and replace postcss-loader with @tailwindcss/webpack. */functionreplacePostcssLoader(rules){if(!Array.isArray(rules))returnfor(construleofrules){if(!rule)continueif(rule.oneOf)replacePostcssLoader(rule.oneOf)if(rule.rules)replacePostcssLoader(rule.rules)if(Array.isArray(rule.use)){for(leti=0;i<rule.use.length;i++){constloader=rule.use[i]constloaderPath=typeofloader==='string' ? loader : loader?.loaderif(loaderPath&&loaderPath.includes('postcss-loader')){rule.use[i]='@tailwindcss/webpack'}}}}}module.exports=tailwindPlugin
Reacted by Sébastien Lorber, Lennart, Robert Riemann, Sebastian Fritsch and Roy
Activity
[-]Move to Tailwind[/-][+]Move to Tailwind / Tailwind Preset[/+]slorber commentedon Jun 18, 2020
Hi,
I'm not very familar with Tailwind yet.
Currently Infima is a css lib with a few postcss. But it also includes some lightweight vanilla JS components
If I understand correctly, you mean we could implement current Infima CSS classes as a Tailwind preset, instead of the existing css/postcss ?
So we would publish that preset and enable users to extend / customize it more easily?
I see the value of Tailwind, and a similar goal of styling co-located to the markup.
Its scope is larger than current Infima:
jaredpalmer commentedon Jun 18, 2020
Yes you can and should always purge unused tailwind css. Only the classes actually used in the codebase are kept.
kvnxiao commentedon Nov 29, 2020
Hoping this is helpful information, as I got TailwindCSS v2 to properly work with the PostCSS config that Docusaurus v2 already uses.
I'm using a custom
configureWebpackplugin in a fileplugins/my-loaders/index.jslike so:with
package.jsonreferencing a local module dependency"my-loaders": "file:plugins/my-loaders",anddocusaurus.config.jsplugins entry set up asplugins: ['my-loaders'],And a
tailwind.config.jslike so:A reference commit summarizing the above info: Discord4J/documentation@2019279
Note that the PostCSS version in which Docusaurus v2 currently uses is 7.0.XX, while the latest version of PostCSS is 8.0.X and TailwindCSS v2 by default uses PostCSS V8. I had to use a v7 compatibility install of TailwindCSS v2 for this to all work:
"tailwindcss": "npm:@tailwindcss/postcss7-compat"in package.json dependencies.I'm thinking that maybe tailwindcss can be added directly to the https://github.com/facebook/docusaurus/blob/master/packages/docusaurus/src/webpack/utils.ts#L64-L71 plugin block for
getStyleLoaderswith PurgeCSS configured for first class support. Since tailwindcss has PurgeCSS enabled, users who don't use tailwindcss will never see it or even know because all the tailwindcss related css rules will be removed. And there should be no performance penalties in terms of time spent compiling for users who don't import tailwindcss into their .css files or index.js/index.tsx.EDIT: With the newer versions of Docusaurus v2 supporting a configurePostCss option in a plugin, the above code snippet should be changed to the following:
slorber commentedon Nov 30, 2020
Thanks for these infos.
We'll look at this more in depth soon, as we'll work on our theme gallery (#3522) and Tailwind support is part of it
clairefro commentedon Dec 20, 2020
@kvnxiao I tried your config for tailwind and can't seem to get past this error (looks like it's still looking for postcss 8):
Do you have a working repo I could take a look at?
kvnxiao commentedon Dec 20, 2020
@clairefro https://github.com/Discord4J/documentation
You will need to install postcss-import
nahtnam commentedon Dec 24, 2020
@kvnxiao's solution is great! I just want to add an improvement to it. If you add the following to your
tailwind.config.js:important: '#tailwind',then it will not affect the docusaurus pages. Then all you need to do is add<div id="tailwind">around the pages that you want to use tailwind on!wibed commentedon Dec 27, 2020
@kvnxiao
according to postcss/postcss-import#435
postcss-import@^12 (current ^14) is based on postcss8
also the install guide on tailwindcss does not mention the postcss-import module
https://tailwindcss.com/docs/installation#post-css-7-compatibility-build
why did you made it a dependency on your module?
49 remaining items
Karkunow commentedon Sep 12, 2024
Have this one been resolved?
slorber commentedon Sep 13, 2024
This hasn't been resolved and is not currently being worked on.
I'm currently working on making Docusaurus much faster, notably by adopting Rust tools like Rspack, SWC, and LightningCSS.
For that, we need to get rid of PostCSS, which is currently needed for Tailwind. In v4 with Oxide Tailwind will also adopt LightningCSS (details).
We'll look into adding first-class Tailwind support, and a Tailwind theme, once we both successfully adopt LightningCSS.
cemerick commentedon Sep 26, 2024
@kvnxiao's (revised/edited) recipe in #2961 (comment) works quite well (better to snoop around in the Discord4J project they linked IMO to see how everything is laid out), with the addition that
@tailwindentries need to be added to one'scustom.cssfile, e.g.This is standard fare for a tailwind project ofc, but I neglected to do this at first (I guess I thought postcss would somehow roll things up without those rules), and so thought the tailwind+docusaurus integration wasn't working for a while.
rjvim commentedon Oct 9, 2024
I have setup Tailwind recently on Docusaurus 3.5, here is the commit: betalectic/betalectic.github.io@55a5c53
Thanks to various contributors above.
cc @Abhishek-Beta
Change on 16th Oct, need to add following before for before/after of tailwindcss to work
In plugin use the latest tailwind preflight file:
clicktodev commentedon Feb 1, 2025
Looks like this is approachable now that tw v4 is officially out.
Nextra uses tw under the hood so it might a good idea to take a look at their implementation
artemkovalyov commentedon Apr 2, 2025
Tailwind 4 would be a great variant or even replacement for utility first approach. Having it as an option would be a killer. Infima is good but feels underweight for the range of use-cases Docusaurus has seen use for. Some well-positioned framework should work just fine and ensure so needed extensibility.
shirakaba commentedon Apr 17, 2025
So desparate for an official Tailwind theme. Infima overrides everything. I can't even do something as simple as expressing
m-0for resetting an<h1>to zero margin, because Infima's invasive styles are on a higher-priority layer than Tailwind. The only way to outprioritise Infima is to use inline styles, which means just throwing away Tailwind.clicktodev commentedon Apr 17, 2025
Try setting important to true in the tw js config
slorber commentedon Apr 17, 2025
Creating a new Tailwind theme and overriding Infima things are 2 separate problems.
If Infima default/global styles are annoying, the issue to track is #6032
We may find a CSS solution that doesn't require introducing Tailwind. Creating a Tailwind theme remains a goal, but people who don't want Tailwind should also be able to customize things without being annoyed by Infima.
clicktodev commentedon Apr 17, 2025
set important to true and disable tailwind preflight
clicktodev commentedon Apr 17, 2025
Also add a prefix in the config to avoid conflicting class names
slorber commentedon Feb 19, 2026
FYI Tailwind v4.2 just released a new webpack plugin (actually, it's a webpack loader): https://github.com/tailwindlabs/tailwindcss/releases/tag/v4.2.0
Apparently, using this integration is much faster than using postcss for frameworks like Next.js (with both webpack and Turbopack)
If anyone gives this plugin a try, please share how to set it up and if it works well.
webbertakken commentedon Feb 19, 2026
Will give it a try after work
webbertakken commentedon Feb 19, 2026
Had a quick look. Seems to work fine, without any warnings.
There's a couple of postcss related plugins configured in docusaurus webpack that need to be skipped in favour of using the new plugin (including lightning CSS, which is the core engine for Tailwind 4).
Docusaurus doesn't offer a hook to swap out those plugins, so a small custom plugin is required.
The approach I used is to use configureWebpack() (instead of the current configurePostCss()) to walk the webpack rules and replace
postcss-loaderwith@tailwindcss/webpack.Details
Replace the PostCSS-based Tailwind integration with the new dedicated webpack loader, eliminating PostCSS as a middleman.
Deps changed
Configuring the plugin
The plugin (before)
The plugin (after)
src/plugins/tailwind-config.cjs— replaceconfigurePostCss()withconfigureWebpack()