Skip to content

Commit 2afd7b8

Browse files
Upgrade guide changes (#2079)
Closes tailwindlabs/tailwindcss#16372 Closes tailwindlabs/tailwindcss#16395 - Adds a section about the changes to how prefixes work - Adds a section about `space-x-*` and `space-y-*` utility changes - Adds a section about dialogs now having margins in preflight --------- Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
1 parent ecfb11b commit 2afd7b8

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

src/docs/upgrade-guide.mdx

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,37 @@ To update your project for this change, replace any usage of `ring` with `ring-3
365365
<input class="ring-3 ring-blue-500" />
366366
```
367367

368+
### Space-between selector
369+
370+
We've changed the selector used by the [`space-x-*` and `space-y-*` utilities](/docs/margin#adding-space-between-children) to address serious performance issues on large pages:
371+
372+
```css
373+
/* [!code filename:CSS] */
374+
/* Before */
375+
.space-y-4 > :not([hidden]) ~ :not([hidden]) {
376+
margin-top: 1rem;
377+
}
378+
379+
/* Now */
380+
.space-y-4 > :not(:last-child) {
381+
margin-bottom: 1rem;
382+
}
383+
```
384+
385+
You might see changes in your project if you were ever using these utilities with inline elements, or if you were adding other margins to child elements to tweak their spacing.
386+
387+
If this change causes any issues in your project, we recommend migrating to a flex or grid layout and using `gap` instead:
388+
389+
{/* prettier-ignore */}
390+
```html
391+
<!-- [!code filename:HTML] -->
392+
<div class="space-y-4 p-4"> <!-- [!code --] -->
393+
<div class="flex flex-col gap-4 p-4"> <!-- [!code ++] -->
394+
<label for="name">Name</label>
395+
<input type="text" name="name" />
396+
</div>
397+
```
398+
368399
### Container configuration
369400

370401
In v3, the `container` utility had several configuration options like `center` and `padding` that no longer exist in v4.
@@ -478,6 +509,66 @@ If you'd like to continue using `cursor: pointer` by default, add these base sty
478509
}
479510
```
480511

512+
#### Dialog margins removed
513+
514+
Preflight now resets margins on `<dialog>` elements to be consistent with how other elements are reset.
515+
516+
If you still want dialogs to be centered by default, add this CSS to your project:
517+
518+
```css
519+
/* [!code filename:CSS] */
520+
@layer base {
521+
dialog {
522+
margin: auto;
523+
}
524+
}
525+
```
526+
527+
### Using a prefix
528+
529+
Prefixes now look like variants and are always at the beginning of the class name:
530+
531+
```html
532+
<!-- [!code classes:tw:bg-red-500,tw:flex,tw:hover:bg-red-600] -->
533+
<div class="tw:flex tw:bg-red-500 tw:hover:bg-red-600">
534+
<!-- ... -->
535+
</div>
536+
```
537+
538+
When using a prefix, you should still configure your theme variables as if you aren't using a prefix:
539+
540+
```css {{ filename: "app.css" }}
541+
@import "tailwindcss" prefix(tw);
542+
543+
@theme {
544+
--font-display: "Satoshi", "sans-serif";
545+
546+
--breakpoint-3xl: 1920px;
547+
548+
--color-avocado-100: oklch(0.99 0 0);
549+
--color-avocado-200: oklch(0.98 0.04 113.22);
550+
--color-avocado-300: oklch(0.94 0.11 115.03);
551+
552+
/* ... */
553+
}
554+
```
555+
556+
The generated CSS variables _will_ include a prefix to avoid conflicts with any existing variables in your project:
557+
558+
```css {{ filename: "dist.css" }}
559+
:root {
560+
--tw-font-display: "Satoshi", "sans-serif";
561+
562+
--tw-breakpoint-3xl: 1920px;
563+
564+
--tw-color-avocado-100: oklch(0.99 0 0);
565+
--tw-color-avocado-200: oklch(0.98 0.04 113.22);
566+
--tw-color-avocado-300: oklch(0.94 0.11 115.03);
567+
568+
/* ... */
569+
}
570+
```
571+
481572
### Adding custom utilities
482573

483574
In v3, any custom classes you defined within `@layer utilities` would get picked up by Tailwind as a true utility class and would automatically work with variants like `hover`, `focus`, or `lg`.

0 commit comments

Comments
 (0)