|
1 | 1 | ---
|
2 |
| -title: Tailwind CSS v4.0-beta |
3 |
| -description: Using responsive utility variants to build adaptive user interfaces. |
| 2 | +section: Prerelease Documentation |
| 3 | +title: Tailwind CSS v4.0 Beta |
| 4 | +description: Preview what's coming in the next version of Tailwind CSS. |
4 | 5 | ---
|
5 | 6 |
|
6 | 7 | import { Heading } from '@/components/Heading'
|
7 | 8 | import { TipGood, TipBad } from '@/components/Tip'
|
8 | 9 |
|
| 10 | +{/* |
9 | 11 | - Introduction, has a graphic or code sample
|
10 | 12 | - Link to blog post
|
11 | 13 | - Summarize improvements
|
12 | 14 | - Talk about upgrade + link to upgrade section
|
13 | 15 | - Mention breaking changes, link to those
|
| 16 | +*/} |
14 | 17 |
|
15 | 18 | ## Getting started
|
16 | 19 |
|
17 | 20 | ### Installing with Vite
|
18 | 21 |
|
| 22 | +If you're using Vite or a Vite-powered framework like SvelteKit or Remix, install Tailwind along with our new dedicated Vite plugin: |
| 23 | + |
| 24 | +```bash {{ filename: 'Terminal' }} |
| 25 | +$ npm install tailwindcss@next @tailwindcss/vite@next |
| 26 | +``` |
| 27 | + |
| 28 | +Next, add our Vite plugin to your `vite.config.ts` file: |
| 29 | + |
| 30 | +```ts {{ filename: 'vite.config.ts' }} |
| 31 | + import { defineConfig } from 'vite'; |
| 32 | +> import tailwindcss from '@tailwindcss/vite'; |
| 33 | + |
| 34 | + export default defineConfig({ |
| 35 | + plugins: [ |
| 36 | +> tailwindcss() |
| 37 | + ], |
| 38 | + }); |
| 39 | +``` |
| 40 | + |
| 41 | +Finally, import Tailwind into your main CSS file: |
| 42 | + |
| 43 | +```css {{ filename: 'src/index.css' }} |
| 44 | +> @import "tailwindcss"; |
| 45 | +``` |
| 46 | + |
19 | 47 | ### Installing with PostCSS
|
20 | 48 |
|
| 49 | +If your project uses PostCSS or you're using a framework like Next.js that supports PostCSS plugins, install Tailwind along with our new dedicated PostCSS plugin: |
| 50 | + |
| 51 | +```bash {{ filename: 'Terminal' }} |
| 52 | +$ npm install tailwindcss@next @tailwindcss/postcss@next |
| 53 | +``` |
| 54 | + |
| 55 | +Next, add our PostCSS plugin to your `postcss.config.js` file: |
| 56 | + |
| 57 | +```ts {{ filename: 'postcss.config.mjs' }} |
| 58 | + export default { |
| 59 | + plugins: { |
| 60 | +> '@tailwindcss/postcss': {}, |
| 61 | + }, |
| 62 | + }; |
| 63 | +``` |
| 64 | + |
| 65 | +Finally, import Tailwind into your main CSS file: |
| 66 | + |
| 67 | +```css {{ filename: 'app.css' }} |
| 68 | +> @import "tailwindcss"; |
| 69 | +``` |
| 70 | + |
21 | 71 | ### Installing the CLI
|
22 | 72 |
|
| 73 | +If you want to use our dedicated CLI tool, install Tailwind along with our new dedicated CLI package: |
| 74 | + |
| 75 | +```bash {{ filename: 'Terminal' }} |
| 76 | +$ npm install tailwindcss@next @tailwindcss/cli@next |
| 77 | +``` |
| 78 | + |
| 79 | +Next, import Tailwind into your main CSS file: |
| 80 | + |
| 81 | +```css {{ filename: 'app.css' }} |
| 82 | +> @import "tailwindcss"; |
| 83 | +``` |
| 84 | + |
| 85 | +Then compile your CSS using the CLI tool: |
| 86 | +```bash {{ filename: 'Terminal' }} |
| 87 | +$ npx @tailwindcss/cli -i input.css -o output.css |
| 88 | +``` |
| 89 | + |
| 90 | +You can also download [standalone builds](https://github.com/tailwindlabs/tailwindcss/releases/tag/v4.0.0-beta-1) of the new CLI tool from GitHub for projects that don't otherwise depend on the Node.js ecosystem. |
| 91 | + |
23 | 92 | ### Upgrading from v3
|
24 | 93 |
|
| 94 | +If you'd like to try upgrading a project from v3 to the v4 beta releases, you can use our upgrade tool to do the vast majority of the heavy lifting for you: |
| 95 | + |
| 96 | +```bash {{ filename: 'Terminal' }} |
| 97 | +$ npx @tailwindcss/upgrade@next |
| 98 | +``` |
| 99 | + |
| 100 | +For most projects, the upgrade tool will automate the entire migration process including: |
| 101 | + |
| 102 | +- **Updating dependencies** like Tailwind itself, adding the new PostCSS plugin, updating our Prettier plugin if you have it installed, and removing dependencies that are no longer needed like `postcss-import` and `autoprefixer`. |
| 103 | +- **Replacing `@tailwind` directives with `@import "tailwindcss"`** to modernize your project. |
| 104 | +- **Migrating your config file to CSS** if possible, or updating your CSS to import your config file with `@config`. |
| 105 | +- **Replacing deprecated utility classes** with their v4 equivalents, like renaming `outline-none` to `outline-hidden`. |
| 106 | +- **Updating your variant order** so that order-sensitive variants in your utilities are sorted from left to right instead of right to left. |
| 107 | +- **Replacing `theme(…)` with `var(…)`** where possible, taking advantage of the CSS variables generated in v4.0 by default. |
| 108 | +- **Migrating to the new variable shorthand syntax**, updating utilities like `bg-[--my-color]` to `bg-(--my-color)`. |
| 109 | +- **Adding compatibility base styles for Preflight changes**, so your project looks the same after upgrading. |
| 110 | +- **Updating custom utilities to use `@utility`** instead of just custom classes in the `utilities` layer. |
| 111 | +- **Updating existing imports to use layers** to make sure your custom styles behave as expected with Tailwind's layered styles. |
| 112 | + |
| 113 | +**We recommend running the upgrade tool in a new branch**, then carefully reviewing the diff and testing your project in the browser to make sure all of the changes look correct. You may need to tweak a few things by hand in complex projects, but the tool will save you a ton of time either way. |
| 114 | + |
| 115 | +It's also a good idea to go over all of the [breaking changes](#breaking-changes) in v4.0 and get a good understanding of what's changed, in case there are other things you need to update in your project that the upgrade tool doesn't catch. |
| 116 | + |
| 117 | + |
25 | 118 | ---
|
26 | 119 |
|
27 |
| -## What's new in v4 |
| 120 | +## What's new in v4.0 |
28 | 121 |
|
29 | 122 | ### CSS-first configuration
|
30 | 123 |
|
@@ -154,4 +247,8 @@ import { TipGood, TipBad } from '@/components/Tip'
|
154 | 247 |
|
155 | 248 | ### Hover styles ignored on mobile
|
156 | 249 |
|
157 |
| -### Core plugins cannot be disabled |
| 250 | +### Core plugins cannot be disabled |
| 251 | + |
| 252 | +### Using a JavaScript config file |
| 253 | + |
| 254 | +- Not autodetected, need to use `@config` |
0 commit comments