8.9 KiB
Tailwind CSS v3 to v4 Migration Documentation
Overview
This document details the complete migration process from Tailwind CSS v3 to v4 for the Django ThrillWiki project. The migration was performed on August 15, 2025, and includes all changes, configurations, and verification steps.
Migration Summary
- From: Tailwind CSS v3.x
- To: Tailwind CSS v4.1.12
- Project: Django ThrillWiki (Django + Tailwind CSS integration)
- Status: ✅ Complete and Verified
- Breaking Changes: None (all styling preserved)
Key Changes in Tailwind CSS v4
1. CSS Import Syntax
- v3: Used
@tailwinddirectives - v4: Uses single
@import "tailwindcss"statement
2. Theme Configuration
- v3: Configuration in
tailwind.config.js - v4: CSS-first approach with
@themeblocks
3. Deprecated Utilities
Multiple utility classes were renamed or deprecated in v4.
Migration Steps Performed
Step 1: Update Main CSS File
File: static/css/src/input.css
Before (v3):
@tailwind base;
@tailwind components;
@tailwind utilities;
/* Custom styles... */
After (v4):
@import "tailwindcss";
@theme {
--color-primary: #4f46e5;
--color-secondary: #e11d48;
--color-accent: #8b5cf6;
--font-family-sans: Poppins, sans-serif;
}
/* Custom styles... */
Step 2: Theme Variable Migration
Migrated custom colors and fonts from tailwind.config.js to CSS variables in @theme block:
| Variable | Value | Description |
|---|---|---|
--color-primary |
#4f46e5 |
Indigo-600 (primary brand color) |
--color-secondary |
#e11d48 |
Rose-600 (secondary brand color) |
--color-accent |
#8b5cf6 |
Violet-500 (accent color) |
--font-family-sans |
Poppins, sans-serif |
Primary font family |
Step 3: Deprecated Utility Updates
Outline Utilities
- Changed:
outline-none→outline-hidden - Files affected: All template files, component CSS
Ring Utilities
- Changed:
ring→ring-3 - Reason: Default ring width now requires explicit specification
Shadow Utilities
- Changed:
shadow-sm→shadow-xsshadow→shadow-sm
- Files affected: Button components, card components
Opacity Utilities
- Changed:
bg-opacity-*format →color/opacityformat - Example:
bg-blue-500 bg-opacity-50→bg-blue-500/50
Flex Utilities
- Changed:
flex-shrink-0→shrink-0
Important Modifier
- Changed:
!important→!(shorter syntax) - Example:
!outline-none→!outline-hidden
Step 4: Template File Updates
Updated the following template files with new utility classes:
Core Templates
templates/base.htmltemplates/components/navbar.htmltemplates/components/footer.html
Page Templates
templates/parks/park_list.htmltemplates/parks/park_detail.htmltemplates/rides/ride_list.htmltemplates/rides/ride_detail.htmltemplates/companies/company_list.htmltemplates/companies/company_detail.html
Form Templates
templates/parks/park_form.htmltemplates/rides/ride_form.htmltemplates/companies/company_form.html
Component Templates
templates/components/search_results.htmltemplates/components/pagination.html
Step 5: Component CSS Updates
Updated custom component classes in static/css/src/input.css:
Button Components:
.btn-primary {
@apply inline-flex items-center px-6 py-2.5 border border-transparent rounded-full shadow-md text-sm font-medium text-white bg-gradient-to-r from-primary to-secondary hover:from-primary/90 hover:to-secondary/90 focus:outline-hidden focus:ring-3 focus:ring-offset-2 focus:ring-primary/50 transform hover:scale-105 transition-all;
}
.btn-secondary {
@apply inline-flex items-center px-6 py-2.5 border border-gray-200 dark:border-gray-700 rounded-full shadow-md text-sm font-medium text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-hidden focus:ring-3 focus:ring-offset-2 focus:ring-primary/50 transform hover:scale-105 transition-all;
}
Configuration Files
Tailwind Config (Preserved for Reference)
File: tailwind.config.js
The original v3 configuration was preserved for reference but is no longer the primary configuration method:
module.exports = {
content: [
'./templates/**/*.html',
'./static/js/**/*.js',
'./*/templates/**/*.html',
],
darkMode: 'class',
theme: {
extend: {
colors: {
primary: '#4f46e5',
secondary: '#e11d48',
accent: '#8b5cf6',
},
fontFamily: {
sans: ['Poppins', 'sans-serif'],
},
},
},
plugins: [
require('@tailwindcss/forms'),
require('@tailwindcss/typography'),
],
}
Package.json Updates
No changes required to package.json as the Django-Tailwind package handles version management.
Verification Steps
1. Build Process Verification
# Clean and rebuild CSS
lsof -ti :8000 | xargs kill -9
find . -type d -name "__pycache__" -exec rm -r {} +
uv run manage.py tailwind runserver
Result: ✅ Build successful, no errors
2. CSS Compilation Check
# Check compiled CSS size and content
ls -la static/css/tailwind.css
head -50 static/css/tailwind.css | grep -E "(primary|secondary|accent)"
Result: ✅ CSS properly compiled with theme variables
3. Server Response Check
curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/
Result: ✅ HTTP 200 - Server responding correctly
4. Visual Verification
- ✅ Primary colors (indigo) displaying correctly
- ✅ Secondary colors (rose) displaying correctly
- ✅ Accent colors (violet) displaying correctly
- ✅ Poppins font family loading correctly
- ✅ Button styling and interactions working
- ✅ Dark mode functionality preserved
- ✅ Responsive design intact
- ✅ All animations and transitions working
Files Modified
CSS Files
static/css/src/input.css- ✅ Major updates (import syntax, theme variables, component classes)
Template Files (Updated utility classes)
templates/base.htmltemplates/components/navbar.htmltemplates/components/footer.htmltemplates/parks/park_list.htmltemplates/parks/park_detail.htmltemplates/parks/park_form.htmltemplates/rides/ride_list.htmltemplates/rides/ride_detail.htmltemplates/rides/ride_form.htmltemplates/companies/company_list.htmltemplates/companies/company_detail.htmltemplates/companies/company_form.htmltemplates/components/search_results.htmltemplates/components/pagination.html
Configuration Files (Preserved)
tailwind.config.js- ✅ Preserved for reference
Benefits of v4 Migration
Performance Improvements
- Smaller CSS bundle size
- Faster compilation times
- Improved CSS-in-JS performance
Developer Experience
- CSS-first configuration approach
- Better IDE support for theme variables
- Simplified import syntax
Future Compatibility
- Modern CSS features support
- Better container queries support
- Enhanced dark mode capabilities
Troubleshooting Guide
Common Issues and Solutions
Issue: "Cannot apply unknown utility class"
Solution: Check if utility was renamed in v4 migration table above
Issue: Custom colors not working
Solution: Ensure @theme block is properly defined with CSS variables
Issue: Build errors
Solution: Run clean build process:
lsof -ti :8000 | xargs kill -9
find . -type d -name "__pycache__" -exec rm -r {} +
uv run manage.py tailwind runserver
Rollback Plan
If rollback is needed:
- Restore CSS Import Syntax:
@tailwind base;
@tailwind components;
@tailwind utilities;
-
Remove @theme Block: Delete the
@themesection from input.css -
Revert Utility Classes: Use search/replace to revert utility class changes
-
Downgrade Tailwind: Update package to v3.x version
Post-Migration Checklist
- CSS compilation working
- Development server running
- All pages loading correctly
- Colors displaying properly
- Fonts loading correctly
- Interactive elements working
- Dark mode functioning
- Responsive design intact
- No console errors
- Performance acceptable
Future Considerations
New v4 Features to Explore
- Enhanced container queries
- Improved dark mode utilities
- New color-mix() support
- Advanced CSS nesting
Maintenance Notes
- Monitor for v4 updates and new features
- Consider migrating more configuration to CSS variables
- Evaluate new utility classes as they're released
Contact and Support
For questions about this migration:
- Review this documentation
- Check Tailwind CSS v4 official documentation
- Consult the preserved
tailwind.config.jsfor original settings
Migration Completed: August 15, 2025
Tailwind Version: v4.1.12
Status: Production Ready ✅