|
| 1 | +--- |
| 2 | +description: Tailwind CSS usage and configuration standards for this repository. |
| 3 | +applyTo: "**/*.{css,vue,js,ts,jsx,tsx}" |
| 4 | +--- |
| 5 | + |
| 6 | +# Tailwind CSS Instructions |
| 7 | + |
| 8 | +## Version |
| 9 | +- Use Tailwind CSS v4 or higher. Do not use older versions. |
| 10 | +- Tailwind v4+ does not use `@config` or JavaScript/TypeScript config files. All configuration is handled via CSS and utility classes. |
| 11 | + |
| 12 | +## Customizing Colors |
| 13 | +- To use custom colors, use Tailwind's built-in color palette and utility classes (e.g., `bg-blue-600`, `text-primary`). |
| 14 | +- For custom colors, you can: |
| 15 | + - Use the `style` attribute for one-off values. |
| 16 | + - Do not use arbitrary color values (e.g. `bg-[#0ea5e9]`). Always use colors defined in your `@theme` block for consistency and maintainability. |
| 17 | + - Define custom CSS variables with the `@theme` directive and use them in your utility classes. |
| 18 | + |
| 19 | +### Example: Customizing Colors with @theme |
| 20 | + |
| 21 | +```css |
| 22 | +@import "tailwindcss"; |
| 23 | +@theme { |
| 24 | + --color-midnight: #121063; |
| 25 | + --color-tahiti: #3ab7bf; |
| 26 | + --color-bermuda: #78dcca; |
| 27 | +} |
| 28 | + |
| 29 | +.btn-tahiti { |
| 30 | + @apply bg-[--color-tahiti] text-white font-semibold px-4 py-2 rounded; |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +```vue |
| 35 | +<template> |
| 36 | + <button class="btn-tahiti hover:bg-[--color-bermuda]">Custom Color</button> |
| 37 | +</template> |
| 38 | +``` |
| 39 | + |
| 40 | +See the [Tailwind CSS Colors documentation](https://tailwindcss.com/docs/colors) for more details on using and customizing colors. |
| 41 | + |
| 42 | +## Usage |
| 43 | +- Use Tailwind utility classes directly in your HTML, Vue, or JSX/TSX templates. |
| 44 | +- Prefer semantic and accessible markup; combine Tailwind with best practices from the HTML and accessibility instructions. |
| 45 | +- To use `@apply` in a Vue component's `<style>` block, you must reference TailwindCSS at the top of the style section: |
| 46 | + |
| 47 | + ```vue |
| 48 | + <template> |
| 49 | + <h1>Hello world!</h1> |
| 50 | + </template> |
| 51 | + <style> |
| 52 | + @reference "tailwindcss"; |
| 53 | + h1 { |
| 54 | + @apply text-2xl font-bold text-red-500; |
| 55 | + } |
| 56 | + </style> |
| 57 | + ``` |
| 58 | +- Use `@apply` for extracting repeated utility patterns into custom classes in your CSS modules or component styles. |
| 59 | +- Do not override Tailwind base styles globally unless absolutely necessary. |
| 60 | + |
| 61 | +## Best Practices |
| 62 | +- Keep utility class lists short and readable; extract to custom classes if they become too long. |
| 63 | +- Use responsive and state variants (e.g., `md:`, `hover:`) as needed for interactivity and layout. |
| 64 | +- Use Tailwind's color palette and spacing scale for consistency. |
| 65 | +- Avoid using arbitrary values. Always use colors and spacing defined in your `@theme` block or Tailwind's default palette for consistency. |
| 66 | +- Do not use deprecated or removed features from earlier Tailwind versions. |
| 67 | + |
| 68 | + |
| 69 | +## Example |
| 70 | + |
| 71 | + |
| 72 | +### Custom Components with @layer |
| 73 | + |
| 74 | +To add custom component classes (such as buttons or cards), use the `@layer components` directive: |
| 75 | +### Custom Utilities with @utility |
| 76 | + |
| 77 | +To define custom utility classes, use the `@utility` directive: |
| 78 | + |
| 79 | +```css |
| 80 | +@utility content-auto { |
| 81 | + content-visibility: auto; |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +```css |
| 86 | +@import "tailwindcss"; |
| 87 | +@theme { |
| 88 | + --color-white: #fff; |
| 89 | + --radius-lg: 0.5rem; |
| 90 | + --spacing-6: 1.5rem; |
| 91 | + --shadow-xl: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1); |
| 92 | +} |
| 93 | + |
| 94 | +@layer components { |
| 95 | + .card { |
| 96 | + background-color: var(--color-white); |
| 97 | + border-radius: var(--radius-lg); |
| 98 | + padding: var(--spacing-6); |
| 99 | + box-shadow: var(--shadow-xl); |
| 100 | + } |
| 101 | + .btn-primary { |
| 102 | + @apply px-4 py-2 rounded bg-[--color-primary] text-white font-semibold hover:bg-[--color-primary-hover]; |
| 103 | + } |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +### Variants with @variant |
| 108 | + |
| 109 | +To define variants (such as dark mode), use the `@variant` directive: |
| 110 | + |
| 111 | +```css |
| 112 | +.my-element { |
| 113 | + background: white; |
| 114 | + @variant dark { |
| 115 | + background: black; |
| 116 | + } |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +```vue |
| 121 | +<template> |
| 122 | + <div class="card">Card content</div> |
| 123 | + <button class="btn-primary">Click me</button> |
| 124 | +</template> |
| 125 | +``` |
| 126 | + |
| 127 | +## References |
| 128 | +- [Tailwind CSS v4 Documentation](https://tailwindcss.com/docs/installation) |
0 commit comments