Skip to content

Commit 262cfd7

Browse files
Add section about prefix(…) (#2040)
Closes #2014 This adds a section about how to use the `prefix(…)` option to the `/styling-with-utility-classes` docs. --------- Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
1 parent 3d2b156 commit 262cfd7

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/docs/styling-with-utility-classes.mdx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -897,8 +897,6 @@ Again though, for anything that's more complicated than just a single HTML eleme
897897

898898
## Managing style conflicts
899899

900-
{/* All of the styles in Tailwind have fairly low specificity which can lead to style conflicts */}
901-
902900
### Conflicting utility classes
903901

904902
When you add two classes that target the same CSS property, the class that appears later in the stylesheet wins. So in this example, the element will receive `display: grid` even though `flex` comes last in the actual `class` attribute:
@@ -994,3 +992,33 @@ If you're adding Tailwind to a project that has existing complex CSS with high s
994992
```
995993

996994
</CodeExampleStack>
995+
996+
### Using the prefix option
997+
998+
If your project has class names that conflict with Tailwind CSS utilities, you can prefix all Tailwind-generated classes and CSS variables using the `prefix` option:
999+
1000+
<CodeExampleStack>
1001+
1002+
```css
1003+
/* [!code filename:app.css] */
1004+
/* [!code word:important] */
1005+
@import "tailwindcss" prefix(tw);
1006+
```
1007+
1008+
```css
1009+
/* [!code filename:Compiled CSS] */
1010+
/* [!code word:tw\:] */
1011+
@layer theme {
1012+
:root {
1013+
--tw-color-red-500: oklch(0.637 0.237 25.331);
1014+
}
1015+
}
1016+
1017+
@layer utilities {
1018+
.tw\:text-red-500 {
1019+
color: var(--tw-color-red-500);
1020+
}
1021+
}
1022+
```
1023+
1024+
</CodeExampleStack>

0 commit comments

Comments
 (0)