Skip to content

Commit 6b556b6

Browse files
committed
WIP
1 parent 32dc0ca commit 6b556b6

File tree

1 file changed

+157
-3
lines changed

1 file changed

+157
-3
lines changed

src/pages/docs/v4-beta.mdx

Lines changed: 157 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ $ npm install tailwindcss@next @tailwindcss/postcss@next
5454

5555
Next, add our PostCSS plugin to your `postcss.config.js` file:
5656

57-
```ts {{ filename: 'postcss.config.mjs' }}
57+
```js {{ filename: 'postcss.config.mjs' }}
5858
export default {
5959
plugins: {
6060
> '@tailwindcss/postcss': {},
@@ -121,17 +121,171 @@ It's also a good idea to go over all of the [breaking changes](#breaking-changes
121121

122122
### CSS-first configuration
123123

124-
- CSS-first configuration
124+
One of the biggest changes in Tailwind CSS v4.0 is the shift from configuring your project in JavaScript to configuring it in CSS.
125+
126+
Instead of a `tailwind.config.js` file, you can configure all of your customizations directly in the CSS file where you import Tailwind, giving you one less file to worry about in your project:
127+
128+
```css {{ filename: 'app.css', style: 'framed', color: 'sky' }}
129+
@import "tailwindcss";
130+
131+
@theme {
132+
--font-display: "Satoshi", "sans-serif";
133+
134+
--breakpoint-3xl: 1920px;
135+
136+
--color-avocado-100: oklch(0.99 0 0);
137+
--color-avocado-200: oklch(0.98 0.04 113.22);
138+
--color-avocado-300: oklch(0.94 0.11 115.03);
139+
--color-avocado-400: oklch(0.92 0.19 114.08);
140+
--color-avocado-500: oklch(0.84 0.18 117.33);
141+
--color-avocado-600: oklch(0.53 0.12 118.34);
142+
143+
--ease-fluid: cubic-bezier(0.3, 0, 0, 1);
144+
--ease-snappy: cubic-bezier(0.2, 0, 0, 1);
145+
146+
/* ... */
147+
}
148+
```
149+
150+
The new CSS-first configuration lets you do just about everything you could do in your `tailwind.config.js` file, including configuring your design tokens, setting up content sources, defining custom utilities and variants, installing plugins, and more.
151+
152+
To learn more about how it all works, read the [CSS configuration in-depth](#css-configuration-in-depth) documentation.
125153

126154
### CSS theme variables
127155

156+
Tailwind CSS v4.0 takes all of your design tokens and makes them available as CSS variables by default, so you can reference any value you need at run-time using just CSS.
157+
158+
Using the example `@theme` from earlier, all of these values will be added to your CSS to as regular custom properties:
159+
160+
```css {{ filename: 'app.css', style: 'framed', color: 'indigo' }}
161+
:root {
162+
--font-display: "Satoshi", "sans-serif";
163+
164+
--breakpoint-3xl: 1920px;
165+
166+
--color-avocado-100: oklch(0.99 0 0);
167+
--color-avocado-200: oklch(0.98 0.04 113.22);
168+
--color-avocado-300: oklch(0.94 0.11 115.03);
169+
--color-avocado-400: oklch(0.92 0.19 114.08);
170+
--color-avocado-500: oklch(0.84 0.18 117.33);
171+
--color-avocado-600: oklch(0.53 0.12 118.34);
172+
173+
--ease-fluid: cubic-bezier(0.3, 0, 0, 1);
174+
--ease-snappy: cubic-bezier(0.2, 0, 0, 1);
175+
176+
/* ... */
177+
}
178+
```
179+
180+
This makes it easy to reuse these values as inline styles or pass them to libraries like [Motion](https://motion.dev/docs/react-animation#css-variables) to animate them.
181+
128182
### Native CSS cascade layers
129183

184+
We're using real [CSS cascade layers](https://developer.mozilla.org/en-US/docs/Web/CSS/@layer) in v4.0, which make it easier than ever to control the precedence of styles and how they interact with each other.
185+
186+
```css {{ filename: 'dist.css', style: 'framed', color: 'purple', scroll: true }}
187+
@layer theme, base, components, utilities;
188+
189+
@layer theme {
190+
:root {
191+
--font-sans: ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
192+
'Segoe UI Symbol', 'Noto Color Emoji';
193+
--font-serif: ui-serif, Georgia, Cambria, 'Times New Roman', Times, serif;
194+
--font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono',
195+
'Courier New', monospace;
196+
197+
/* ... */
198+
}
199+
}
200+
201+
@layer base {
202+
*,
203+
::after,
204+
::before,
205+
::backdrop,
206+
::file-selector-button {
207+
box-sizing: border-box;
208+
margin: 0;
209+
padding: 0;
210+
border: 0 solid;
211+
}
212+
213+
/* ... */
214+
}
215+
216+
@layer utilities {
217+
.pointer-events-none {
218+
pointer-events: none;
219+
}
220+
.visibility-hidden {
221+
visibility: hidden;
222+
}
223+
224+
/* ... */
225+
226+
.focus\:outline:focus {
227+
outline-width: 1px;
228+
}
229+
230+
@media (width >= 40rem) {
231+
@media (hover: hover) {
232+
.sm\:hover\:opacity-100:hover {
233+
opacity: 100%;
234+
}
235+
}
236+
}
237+
}
238+
```
239+
240+
We've had layers as a concept in Tailwind for years, but native cascade layers can do things that we couldn't easily replicate at build-time, like isolating styles within a layer even if they have a higher specificity than styles in another layer. Less code for us to maintain too!
241+
130242
### Automatic source detection
131243

244+
You know how you always had to configure that annoying `content` array in Tailwind CSS v3? In v4.0, we came up with a bunch of heuristics for detecting all of that stuff automatically so you don't have to configure it at all.
245+
246+
For example, we automatically ignore anything in your `.gitignore` file to avoid scanning dependencies or generated files that aren't under version control:
247+
248+
```bash {{ filename: '.gitignore', style: 'framed', color: 'fuchsia' }}
249+
# dependencies
250+
/node_modules
251+
252+
# testing
253+
/coverage
254+
255+
# caches
256+
/.next/
257+
258+
# production
259+
/build
260+
```
261+
262+
We also automatically ignore all binary extensions like images, videos, .zip files, and more.
263+
264+
And if you ever need to explicitly add a source that's excluded by default, you can always add it with the `@source` directive, right in your CSS file:
265+
266+
```css {{ filename: 'app.css', style: 'framed', color: 'pink' }}
267+
@import "tailwindcss";
268+
> @source "../node_modules/@my-company/ui-lib";
269+
```
270+
271+
The `@source` directive uses the same heuristics under the hood, so it will exclude binary file types for example as well, without you having to specify all of the extensions to scan explicitly.
272+
132273
### Built-in import support
133274

134-
- Built-in `@import` support
275+
Before v4.0, if you wanted to inline other CSS files using `@import` you'd have to configure another plugin like `postcss-import` to handle it for you.
276+
277+
Now we handle this out of the box, so you don't need to include another plugin:
278+
279+
```diff-js {{ filename: 'postcss.config.mjs', style: 'framed', color: 'sky' }}
280+
export default {
281+
plugins: {
282+
- 'postcss-import': {},
283+
'@tailwindcss/postcss': {},
284+
},
285+
};
286+
```
287+
288+
Our import system is purpose-built for Tailwind CSS, so we've also been able to make it even faster by tightly integrating it with our engine.
135289

136290
### Built-in CSS transpilation
137291

0 commit comments

Comments
 (0)