Audit Tailwind CSS usage for best practices and consistency
Analyzes Tailwind CSS usage for consistency, performance, best practices, and v4 compliance issues.
/plugin marketplace add gopherguides/gopher-ai/plugin install tailwind@gopher-ai[path] [--fix]claude-opus-4-5-20251101If $ARGUMENTS is empty or not provided:
Audit Tailwind CSS usage in the current project for best practices, consistency, and optimization opportunities.
Usage: /tailwind-audit [path] [options]
Examples:
/tailwind-audit - Audit entire project/tailwind-audit ./src - Audit specific directory/tailwind-audit --fix - Audit and auto-fix issues where possibleWhat this command checks:
Proceed with auditing the current project.
If $ARGUMENTS is provided:
Parse arguments:
Find all files that may contain Tailwind classes:
# Find template files
fd -e html -e htm -e templ -e jsx -e tsx -e vue -e svelte -e astro -e php -e blade.php -e erb -e hbs -d 5 2>/dev/null | head -100
# Find CSS files
fd -e css -d 5 2>/dev/null | head -20
Check for mixed spacing units:
# Find mixed px values in Tailwind context
grep -r "class=" --include="*.html" --include="*.templ" --include="*.jsx" --include="*.tsx" | grep -E "p-\d|m-\d" | head -20
Look for patterns like:
p-4 alongside padding: 16px (should use only Tailwind)w-[200px] when w-52 (208px) would workgap-4 and space-x-4 in same componentCheck for duplicate/conflicting utilities:
| Issue | Example | Fix |
|---|---|---|
| Duplicate spacing | p-4 p-6 | Remove p-4 |
| Conflicting display | flex block | Choose one |
| Redundant color | bg-blue-500 bg-red-500 | Remove one |
| Overridden responsive | md:flex md:block | Remove one |
Check for inconsistent color usage:
Look for:
bg-[#3b82f6] vs bg-primaryblue-400, blue-500, blue-600 randomlyInline styles that should be utilities:
# Find inline styles
grep -r "style=" --include="*.html" --include="*.templ" --include="*.jsx" --include="*.tsx" | head -20
Common conversions:
| Inline Style | Tailwind Utility |
|---|---|
style="display: flex" | flex |
style="margin: 1rem" | m-4 |
style="padding: 0.5rem 1rem" | py-2 px-4 |
style="font-weight: bold" | font-bold |
style="text-align: center" | text-center |
Use mcp__tailwindcss__convert_css_to_tailwind for complex conversions.
Large arbitrary values:
Look for excessive use of arbitrary values [...]:
@themeClass ordering convention:
Recommended order: layout → spacing → sizing → typography → colors → effects → interactive
Good: "flex items-center gap-4 p-4 w-full text-sm text-gray-700 bg-white shadow-sm hover:bg-gray-50 transition-colors"
Bad: "hover:bg-gray-50 flex bg-white p-4 text-sm shadow-sm w-full gap-4 items-center text-gray-700 transition-colors"
Component extraction candidates:
Find class combinations that appear 3+ times:
# Extract class strings and count duplicates
grep -ohr 'class="[^"]*"' --include="*.html" --include="*.templ" --include="*.jsx" | sort | uniq -c | sort -rn | head -20
Repeated patterns should be extracted:
@layer components {
.btn {
@apply px-4 py-2 rounded-lg font-medium transition-colors;
}
.card {
@apply p-6 bg-card rounded-xl border border-border shadow-sm;
}
}
Accessibility issues:
| Check | Issue | Fix |
|---|---|---|
| Focus indicators | Missing focus: or focus-visible: | Add focus-visible:ring-2 focus-visible:ring-primary |
| Screen reader | Hidden content without sr-only | Add sr-only for visually hidden text |
| Color contrast | Low contrast combinations | Use higher contrast colors |
| Interactive elements | Missing hover/focus states | Add hover: and focus: variants |
Deprecated v3 patterns:
| v3 Pattern | v4 Replacement |
|---|---|
@tailwind base; | @import "tailwindcss"; |
@tailwind components; | (included in import) |
@tailwind utilities; | (included in import) |
tailwind.config.js | @theme { } in CSS |
theme.extend.colors | --color-* in @theme |
darkMode: 'class' | @variant dark { } |
Check for v3 config file:
ls tailwind.config.* 2>/dev/null
If found, recommend using /tailwind-migrate command.
Check CSS file for v4 syntax:
# Should find @import "tailwindcss"
grep -l '@import.*tailwindcss' *.css */*.css 2>/dev/null
# Should NOT find old directives
grep -l '@tailwind' *.css */*.css 2>/dev/null
## Tailwind CSS Audit Report
**Project:** [path]
**Files scanned:** X template files, Y CSS files
**Date:** [current date]
### Summary
| Category | Issues | Auto-fixable |
|----------|--------|--------------|
| Consistency | X | Y |
| Performance | X | Y |
| Best Practices | X | Y |
| v4 Compliance | X | Y |
| **Total** | **X** | **Y** |
### Critical Issues
[List issues that should be fixed immediately]
### Consistency Issues
| File | Line | Issue | Suggestion |
|------|------|-------|------------|
| ... | ... | ... | ... |
### Performance Issues
| File | Line | Issue | Suggestion |
|------|------|-------|------------|
| ... | ... | ... | ... |
### Best Practices
| File | Line | Issue | Suggestion |
|------|------|-------|------------|
| ... | ... | ... | ... |
### Component Extraction Candidates
These class combinations appear 3+ times and could be extracted:
| Pattern | Count | Suggested Name |
|---------|-------|----------------|
| `flex items-center gap-4` | 12 | `.flex-row` |
| `text-sm text-muted-foreground` | 8 | `.text-muted` |
| `px-4 py-2 rounded-lg` | 6 | `.btn-base` |
### v4 Migration Needed
[List any v3 patterns that need migration]
### Recommendations
1. [Prioritized list of improvements]
2. ...
3. ...
When --fix flag is present, automatically fix:
Do NOT auto-fix:
After fixes:
## Auto-Fix Results
Fixed X issues automatically:
- Removed Y duplicate utilities
- Converted Z inline styles
- Reordered W class strings
- Updated V v3 patterns to v4
Remaining issues: X (require manual review)
Files modified:
- path/to/file1.html (3 fixes)
- path/to/file2.templ (2 fixes)
mcp__tailwindcss__search_tailwind_docs to verify utility suggestionsmcp__tailwindcss__get_tailwind_utilities to find equivalent utilities