tailwind.config.js
28 files
Configures Tailwind CSS utility-first framework for the React application.
Defines content scanning, dark mode, theme customization, and plugin setup.
reads this config at build time to generate CSS.
Scans specified files for class usage and tree-shakes unused styles.
CONFIGURATION SECTIONS:
| Section | Purpose |
|---|---|
| content | File paths to scan for classes |
| darkMode | Dark mode strategy |
| theme | Design tokens (colors, fonts, spacing) |
| theme.extend | Add custom tokens without replacing defaults |
| plugins | Third-party Tailwind extensions |
content: [
'./index.html', // Root HTML file
'./src/*\/.{js,ts,jsx,tsx}' // All source files (JS, TS, JSX, TSX)
]
DARK MODE STRATEGY:
| Value | Trigger | Usage |
|---|---|---|
| 'media' | OS preference (prefers-color-scheme) | Automatic based on system |
| 'class' | .dark class on root element | Manual toggle via JavaScript |
THEME EXTENSION:
theme: {
extend: {
colors: {
brand: '#7c3aed',
'brand-dark': '#5b21b6'
},
spacing: {
'128': '32rem'
}
}
}
PLUGINS:
- @tailwindcss/forms - Better form styling
- @tailwindcss/typography - Prose styles
- @tailwindcss/aspect-ratio - Aspect ratio utilities
- @tailwindcss/line-clamp - Line clamping
BUILD PROCESS:
PERFORMANCE:
UTILITY CLASSES:
Tailwind provides thousands of utilities:
RESPONSIVE DESIGN:
Default breakpoints:
| Prefix | Min Width | Target |
|---|---|---|
| (none) | 0px | Mobile-first base |
| sm: | 640px | Small tablets |
| md: | 768px | Tablets |
| lg: | 1024px | Laptops |
| xl: | 1280px | Desktops |
| 2xl: | 1536px | Large screens |
<div className="text-sm md:text-base lg:text-lg">
Responsive text size
</div>
DARK MODE CLASSES:
With darkMode: 'media':
<div className="bg-white dark:bg-gray-900">
Automatically switches based on OS preference
</div>
CUSTOMIZATION EXAMPLES:
Add custom theme values:
theme: {
extend: {
colors: {
'todo-purple': '#7c3aed'
},
fontFamily: {
sans: ['Inter', 'sans-serif']
},
borderRadius: {
'xl': '1rem'
}
}
}
FILE REFERENCES:
KEY CONCEPTS:
@type {import('tailwindcss').Config}