TailwindCSS v4 Migration Guide
Overviewβ
Ring platform has been successfully migrated to TailwindCSS v4, which introduces significant architectural changes including a faster engine, CSS-first configuration, and enhanced features. This migration was completed to leverage the latest performance improvements and modern web features.
Key Changes Madeβ
1. CSS Configuration Migrationβ
Before (v3):
/* Old tailwind.config.ts file + CSS imports */
@tailwind base;
@tailwind components;
@tailwind utilities;
After (v4):
/* All configuration now in CSS */
@import "tailwindcss";
@theme {
--font-inter: var(--font-inter), sans-serif;
--color-purple-500: #8B5CF6;
--color-purple-600: #7C3AED;
--radius: 0.5rem;
/* ... */
}
2. Configuration File Changesβ
- β
Removed:
tailwind.config.ts
(replaced by CSS-first config) - β
Updated:
postcss.config.cjs
to use@tailwindcss/postcss
- β Added: VS Code settings for TailwindCSS v4 support
3. Build System Updatesβ
PostCSS Configuration:
module.exports = {
plugins: {
'@tailwindcss/postcss': {
theme: {
extend: {
colors: {
background: 'var(--background)',
foreground: 'var(--foreground)',
// Enhanced CSS variable support
}
}
}
},
autoprefixer: {}
}
}
New Features Availableβ
1. CSS-First Theme Configurationβ
@theme {
/* Custom colors */
--color-brand: #3b82f6;
--color-accent: #8b5cf6;
/* Custom fonts */
--font-display: "Satoshi", sans-serif;
/* Custom spacing */
--spacing-18: 4.5rem;
}
2. Enhanced Color Opacity Syntaxβ
v3 β v4 Migration:
/* Before */
.example { @apply bg-blue-500 bg-opacity-50; }
/* After */
.example { @apply bg-blue-500/50; }
3. Updated Shadow Utilitiesβ
/* Shadow naming changes */
shadow-xs /* Previously shadow-sm */
shadow-sm /* Previously shadow */
shadow /* New default */
VS Code Integrationβ
Settings Configurationβ
{
"css.customData": [
{
"version": 1.1,
"atDirectives": [
{
"name": "@theme",
"description": "TailwindCSS v4 theme configuration directive"
},
{
"name": "@apply",
"description": "TailwindCSS utility application directive"
}
]
}
],
"css.lint.unknownAtRules": "ignore",
"files.associations": {
"*.css": "tailwindcss"
}
}
Breaking Changes Handledβ
1. Removed Opacity Utilitiesβ
bg-opacity-*
βbg-[color]/[opacity]
text-opacity-*
βtext-[color]/[opacity]
border-opacity-*
βborder-[color]/[opacity]
2. Renamed Utilitiesβ
shadow-sm
βshadow-xs
shadow
βshadow-sm
rounded-sm
βrounded-xs
rounded
βrounded-sm
3. Default Behavior Changesβ
- Border colors now default to
currentColor
- Ring width defaults to 1px (was 3px)
- Enhanced button cursor behavior
Migration Checklistβ
- Replace
@tailwind
directives with@import "tailwindcss"
- Migrate theme configuration from JS to CSS
@theme
block - Remove old config file (
tailwind.config.ts
) - Update PostCSS configuration for v4 compatibility
- Configure VS Code settings for proper syntax highlighting
- Test build process to ensure compatibility
- Verify component styles work correctly
Best Practicesβ
1. Theme Organizationβ
@theme {
/* Colors first */
--color-*: values;
/* Typography */
--font-*: values;
/* Spacing */
--spacing-*: values;
/* Custom properties */
--radius: 0.5rem;
}
2. CSS Variable Usageβ
/* Leverage CSS variables for dynamic theming */
:root {
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
}
.dark {
--background: 222.2 84% 4.9%;
--foreground: 210 40% 98%;
}
3. Component Layer Organizationβ
@layer components {
.button {
@apply px-4 py-2 rounded-sm bg-primary text-primary-foreground;
}
.card {
@apply bg-card text-card-foreground shadow-sm rounded-lg border;
}
}
Performance Benefitsβ
- β‘ Faster Build Times: Up to 10x faster than v3
- π¦ Smaller Bundle Size: More efficient CSS generation
- π Better Hot Reload: Instant style updates during development
- π¨ Enhanced DX: Improved IntelliSense and tooling support
Troubleshootingβ
Common Issuesβ
1. CSS Linting Warnings
// .vscode/settings.json
{
"css.lint.unknownAtRules": "ignore"
}
2. Build Errors
- Ensure
@tailwindcss/postcss
is installed - Check PostCSS configuration syntax
- Verify CSS import order
3. Style Not Applied
- Check for syntax errors in
@theme
block - Verify CSS variable names
- Ensure proper
@layer
usage
Resourcesβ
Migration completed on: 2024-12-XX
Status: β
Production Ready
Performance Impact: +10x faster builds