tailwind-refactor
Community Tailwind CSS Refactoring Best Practices
Comprehensive code quality refactoring guide for Tailwind CSS applications targeting v4. Contains 50 rules across 8 categories, prioritized by migration urgency. Every transformation preserves the existing look and feel — this skill is purely about cleaner code, modern syntax, and v4 compatibility.
Companion skills: Use tailwind-ui-refactor for visual design improvements and tailwind-responsive-ui for responsive layout patterns.
When to Apply
Before manual migration: Run npx @tailwindcss/upgrade first — it handles most configuration and renamed utility changes automatically. Then use this skill for patterns the automated tool does not cover.
Reference these guidelines when:
- Migrating a project from Tailwind CSS v3 to v4
- Cleaning up deprecated or renamed utility classes
- Consolidating verbose multi-class patterns
- Replacing arbitrary values with design tokens
- Removing
@applyoveruse in CSS files - Modernizing syntax to v4 conventions
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Configuration Migration | CRITICAL | config- |
| 2 | Deprecated Utility Replacement | CRITICAL | dep- |
| 3 | Renamed Utility Updates | HIGH | rename- |
| 4 | Class Consolidation | HIGH | class- |
| 5 | Arbitrary Value Cleanup | MEDIUM-HIGH | arb- |
| 6 | Syntax Modernization | MEDIUM | syntax- |
| 7 | @apply & Architecture Cleanup | MEDIUM | arch- |
| 8 | Modern Feature Adoption | LOW-MEDIUM | adopt- |
Quick Reference
1. Configuration Migration (CRITICAL)
config-import-directive- Replace @tailwind directives with @importconfig-css-theme- Migrate tailwind.config.js to CSS @themeconfig-theme-function- Replace theme() function with CSS variablesconfig-theme-inline- Use @theme inline for non-utility design tokensconfig-utility-directive- Replace @layer utilities with @utilityconfig-postcss-plugin- Update PostCSS plugin to @tailwindcss/postcssconfig-content-autodetect- Remove manual content configurationconfig-custom-variant- Migrate addVariant to @custom-variantconfig-preflight-defaults- Account for Preflight default changes in v4
2. Deprecated Utility Replacement (CRITICAL)
dep-opacity-modifiers- Replace -opacity- with opacity modifiers (/50)dep-flex-shorthand- Replace flex-shrink/flex-grow with shrink/growdep-text-ellipsis- Replace overflow-ellipsis with text-ellipsisdep-decoration-utilities- Replace decoration-slice/clone with box-decoration-*dep-transform-composites- Replace transform-none with individual resetsdep-transition-properties- Update transition-[transform] to individual properties
3. Renamed Utility Updates (HIGH)
rename-shadow-scale- Update shadow utilities to new scalerename-blur-scale- Update blur utilities to new scalerename-rounded-scale- Update border radius utilities to new scalerename-ring-width- Replace ring with ring-3 for v3 defaultrename-gradient-utilities- Replace bg-gradient-* with bg-linear-*rename-outline-hidden- Replace outline-none with outline-hidden
4. Class Consolidation (HIGH)
class-size-utility- Replace matching w-* h-* with size-*class-gap-over-space- Prefer gap-* over space-x/y-* in flex/gridclass-inset-shorthand- Replace top/right/bottom/left with inset-*class-border-color-explicit- Add explicit border color for v4 default changeclass-ring-color-explicit- Add explicit ring color for v4 default changeclass-redundant-display- Remove redundant display classesclass-hidden-priority- Remove display overrides for hidden attributeclass-container-utility- Replace container plugin config with @utility
5. Arbitrary Value Cleanup (MEDIUM-HIGH)
arb-hex-to-theme- Replace arbitrary hex colors with theme tokensarb-spacing-to-scale- Replace arbitrary spacing with theme scalearb-dynamic-classes- Avoid dynamic class name constructionarb-breakpoint-to-theme- Replace arbitrary breakpoints with @themearb-zindex-to-scale- Replace arbitrary z-index with defined scale
6. Syntax Modernization (MEDIUM)
syntax-css-variable-parens- Update CSS variable syntax from brackets to parenthesessyntax-variant-stacking- Update variant stacking to left-to-right ordersyntax-important-modifier- Use trailing ! for important modifiersyntax-grid-arbitrary- Use underscores in grid arbitrary valuessyntax-gradient-preservation- Reset gradient stops explicitly in variantssyntax-hover-media-query- Account for hover variant media query wrapping
7. @apply & Architecture Cleanup (MEDIUM)
arch-apply-to-component- Extract @apply blocks into framework componentsarch-layer-to-utility- Replace @layer components with @utilityarch-scoped-reference- Use @reference for @apply in scoped stylesarch-safelist-to-source- Replace safelist with @source inline()arch-domain-composition- Reserve Tailwind for primitives, compose for domain
8. Modern Feature Adoption (LOW-MEDIUM)
adopt-container-queries- Use container queries instead of viewport breakpointsadopt-not-variant- Use not-* variant for negated conditionsadopt-in-variant- Use in-* variant to simplify parent-state stylingadopt-field-sizing- Use field-sizing-content for auto-resizing textareasadopt-starting-variant- Use starting variant for entry animations without JS
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |
More from pproenca/dot-skills
zod
Zod schema validation best practices for type safety, parsing, and error handling. This skill should be used when defining z.object schemas, using z.string validations, safeParse, or z.infer. This skill does NOT cover React Hook Form integration patterns (use react-hook-form skill) or OpenAPI client generation (use orval skill).
2.0Kclean-architecture
Clean Architecture principles and best practices from Robert C. Martin's book. This skill should be used when designing software systems, reviewing code structure, or refactoring applications to achieve better separation of concerns. Triggers on tasks involving layers, boundaries, dependency direction, entities, use cases, or system architecture.
1.4Kemilkowal-animations
Emil Kowalski's animation best practices for web interfaces. Use when writing, reviewing, or implementing animations in React, CSS, or Framer Motion. Triggers on tasks involving transitions, easing, gestures, toasts, drawers, or motion.
917vitest
Vitest testing framework patterns for test setup, async testing, mocking with vi.*, snapshots, and test performance (formerly test-vitest). This skill should be used when writing or debugging Vitest tests. This skill does NOT cover TDD methodology (use test-tdd skill), API mocking with MSW (use test-msw skill), or Jest-specific APIs.
906typescript
This skill should be used when the user asks to "optimize TypeScript performance", "speed up tsc compilation", "configure tsconfig.json", "fix type errors", "improve async patterns", or encounters TS errors (TS2322, TS2339, "is not assignable to"). Also triggers on .ts, .tsx, .d.ts file work involving type definitions, module organization, or memory management. Does NOT cover TypeScript basics, framework-specific patterns, or testing.
820nuqs
nuqs (type-safe URL query state) best practices for Next.js applications. This skill should be used when writing, reviewing, or refactoring code that uses nuqs for URL state management. Triggers on tasks involving useQueryState, useQueryStates, search params, URL state, query parameters, nuqs parsers, or Next.js routing with state.
734