Tailwind CSS is a CSS framework and design system based on Utility Class, which can quickly add common styles to components, and support flexible extension of theme styles.
To use Tailwind CSS in Modern.js, you can follow the steps below:
pnpm run new
in the root directory of your project and make the following selections:After successful initialization, you will see that the package.json
has added dependencies for tailwindcss
and @modern-js/plugin-tailwindcss
.
modern.config.ts
:index.css
file and add the following code:Depending on your needs, you can selectively import the CSS styles provided by Tailwind CSS. Please refer to the @tailwind
documentation for detailed usage of the @tailwind
directive.
index.css
file, for example, add the following code in the root component src/App.jsx
:In Modern.js, you have two ways to configure Tailwind CSS:
tailwind.config.{ts,js}
file, which follows the official usage of Tailwind CSS. Please refer to "Tailwind CSS - Configuration" for more details.Please upgrade Modern.js to version >= 2.33.0 to support automatic reading of tailwind.config.{ts,js}
files.
tailwind.config.{ts,js}
file for configuration.If you are using both the tailwind.config.{ts,js}
file and tools.tailwindcss
option, the configuration defined in tools.tailwindcss
will take precedence and override the content defined in tailwind.config.{ts,js}
.
Tailwind CSS provides an official extension called Tailwind CSS IntelliSense for autocompletion of Tailwind CSS class names, CSS functions, and directives in VS Code.
You can follow the steps below to enable the autocomplete feature:
tailwind.config.{ts,js}
file, you need to create one and write the Tailwind CSS configuration for your current project. Otherwise, the IDE plugin will not work correctly.Modern.js supports both Tailwind CSS v2 and v3 versions, and the framework will recognize the version of the tailwindcss
dependency in the project package.json
file and enable the corresponding configuration. By default, we will install Tailwind CSS v3 version for you.
If your project is still using Tailwind CSS v2, we recommend that you upgrade to v3 to support JIT and other capabilities. For the differences between Tailwind CSS v2 and v3 versions, please refer to the following articles:
Tailwind CSS v2 and v3 do not support the IE 11 browser, please refer to:
If you use Tailwind CSS on IE 11 browser, some styles may not be available, please use it with caution.