File contents 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 @apply overuse 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 @import
config-css-theme - Migrate tailwind.config.js to CSS @theme
config-theme-function - Replace theme() function with CSS variables
config-theme-inline - Use @theme inline for non-utility design tokens
config-utility-directive - Replace @layer utilities with @utility
config-postcss-plugin - Update PostCSS plugin to @tailwindcss/postcss
config-content-autodetect - Remove manual content configuration
config-custom-variant - Migrate addVariant to @custom-variant
config-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/grow
dep-text-ellipsis - Replace overflow-ellipsis with text-ellipsis
dep-decoration-utilities - Replace decoration-slice/clone with box-decoration-*
dep-transform-composites - Replace transform-none with individual resets
dep-transition-properties - Update transition-[transform] to individual properties
3. Renamed Utility Updates (HIGH)
rename-shadow-scale - Update shadow utilities to new scale
rename-blur-scale - Update blur utilities to new scale
rename-rounded-scale - Update border radius utilities to new scale
rename-ring-width - Replace ring with ring-3 for v3 default
rename-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/grid
class-inset-shorthand - Replace top/right/bottom/left with inset-*
class-border-color-explicit - Add explicit border color for v4 default change
class-ring-color-explicit - Add explicit ring color for v4 default change
class-redundant-display - Remove redundant display classes
class-hidden-priority - Remove display overrides for hidden attribute
class-container-utility - Replace container plugin config with @utility
5. Arbitrary Value Cleanup (MEDIUM-HIGH)
arb-hex-to-theme - Replace arbitrary hex colors with theme tokens
arb-spacing-to-scale - Replace arbitrary spacing with theme scale
arb-dynamic-classes - Avoid dynamic class name construction
arb-breakpoint-to-theme - Replace arbitrary breakpoints with @theme
arb-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 parentheses
syntax-variant-stacking - Update variant stacking to left-to-right order
syntax-important-modifier - Use trailing ! for important modifier
syntax-grid-arbitrary - Use underscores in grid arbitrary values
syntax-gradient-preservation - Reset gradient stops explicitly in variants
syntax-hover-media-query - Account for hover variant media query wrapping
7. @apply & Architecture Cleanup (MEDIUM)
arch-apply-to-component - Extract @apply blocks into framework components
arch-layer-to-utility - Replace @layer components with @utility
arch-scoped-reference - Use @reference for @apply in scoped styles
arch-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 breakpoints
adopt-not-variant - Use not-* variant for negated conditions
adopt-in-variant - Use in-* variant to simplify parent-state styling
adopt-field-sizing - Use field-sizing-content for auto-resizing textareas
adopt-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
1 --- 2 name: tailwind-refactor 3 description: Community Tailwind CSS Refactoring Best Practices 4 --- 5 # Community Tailwind CSS Refactoring Best Practices 6 7 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. 8 9 **Companion skills:** Use [tailwind-ui-refactor](../tailwind-ui-refactor/) for visual design improvements and [tailwind-responsive-ui](../tailwind-responsive-ui/) for responsive layout patterns. 10 11 ## When to Apply 12 13 **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. 14 15 Reference these guidelines when: 16 - Migrating a project from Tailwind CSS v3 to v4 17 - Cleaning up deprecated or renamed utility classes 18 - Consolidating verbose multi-class patterns 19 - Replacing arbitrary values with design tokens 20 - Removing `@apply` overuse in CSS files 21 - Modernizing syntax to v4 conventions 22 23 ## Rule Categories by Priority 24 25 | Priority | Category | Impact | Prefix | 26 |----------|----------|--------|--------| 27 | 1 | Configuration Migration | CRITICAL | `config-` | 28 | 2 | Deprecated Utility Replacement | CRITICAL | `dep-` | 29 | 3 | Renamed Utility Updates | HIGH | `rename-` | 30 | 4 | Class Consolidation | HIGH | `class-` | 31 | 5 | Arbitrary Value Cleanup | MEDIUM-HIGH | `arb-` | 32 | 6 | Syntax Modernization | MEDIUM | `syntax-` | 33 | 7 | @apply & Architecture Cleanup | MEDIUM | `arch-` | 34 | 8 | Modern Feature Adoption | LOW-MEDIUM | `adopt-` | 35 36 ## Quick Reference 37 38 ### 1. Configuration Migration (CRITICAL) 39 40 - [`config-import-directive`](references/config-import-directive.md) - Replace @tailwind directives with @import 41 - [`config-css-theme`](references/config-css-theme.md) - Migrate tailwind.config.js to CSS @theme 42 - [`config-theme-function`](references/config-theme-function.md) - Replace theme() function with CSS variables 43 - [`config-theme-inline`](references/config-theme-inline.md) - Use @theme inline for non-utility design tokens 44 - [`config-utility-directive`](references/config-utility-directive.md) - Replace @layer utilities with @utility 45 - [`config-postcss-plugin`](references/config-postcss-plugin.md) - Update PostCSS plugin to @tailwindcss/postcss 46 - [`config-content-autodetect`](references/config-content-autodetect.md) - Remove manual content configuration 47 - [`config-custom-variant`](references/config-custom-variant.md) - Migrate addVariant to @custom-variant 48 - [`config-preflight-defaults`](references/config-preflight-defaults.md) - Account for Preflight default changes in v4 49 50 ### 2. Deprecated Utility Replacement (CRITICAL) 51 52 - [`dep-opacity-modifiers`](references/dep-opacity-modifiers.md) - Replace *-opacity-* with opacity modifiers (/50) 53 - [`dep-flex-shorthand`](references/dep-flex-shorthand.md) - Replace flex-shrink/flex-grow with shrink/grow 54 - [`dep-text-ellipsis`](references/dep-text-ellipsis.md) - Replace overflow-ellipsis with text-ellipsis 55 - [`dep-decoration-utilities`](references/dep-decoration-utilities.md) - Replace decoration-slice/clone with box-decoration-* 56 - [`dep-transform-composites`](references/dep-transform-composites.md) - Replace transform-none with individual resets 57 - [`dep-transition-properties`](references/dep-transition-properties.md) - Update transition-[transform] to individual properties 58 59 ### 3. Renamed Utility Updates (HIGH) 60 61 - [`rename-shadow-scale`](references/rename-shadow-scale.md) - Update shadow utilities to new scale 62 - [`rename-blur-scale`](references/rename-blur-scale.md) - Update blur utilities to new scale 63 - [`rename-rounded-scale`](references/rename-rounded-scale.md) - Update border radius utilities to new scale 64 - [`rename-ring-width`](references/rename-ring-width.md) - Replace ring with ring-3 for v3 default 65 - [`rename-gradient-utilities`](references/rename-gradient-utilities.md) - Replace bg-gradient-* with bg-linear-* 66 - [`rename-outline-hidden`](references/rename-outline-hidden.md) - Replace outline-none with outline-hidden 67 68 ### 4. Class Consolidation (HIGH) 69 70 - [`class-size-utility`](references/class-size-utility.md) - Replace matching w-* h-* with size-* 71 - [`class-gap-over-space`](references/class-gap-over-space.md) - Prefer gap-* over space-x/y-* in flex/grid 72 - [`class-inset-shorthand`](references/class-inset-shorthand.md) - Replace top/right/bottom/left with inset-* 73 - [`class-border-color-explicit`](references/class-border-color-explicit.md) - Add explicit border color for v4 default change 74 - [`class-ring-color-explicit`](references/class-ring-color-explicit.md) - Add explicit ring color for v4 default change 75 - [`class-redundant-display`](references/class-redundant-display.md) - Remove redundant display classes 76 - [`class-hidden-priority`](references/class-hidden-priority.md) - Remove display overrides for hidden attribute 77 - [`class-container-utility`](references/class-container-utility.md) - Replace container plugin config with @utility 78 79 ### 5. Arbitrary Value Cleanup (MEDIUM-HIGH) 80 81 - [`arb-hex-to-theme`](references/arb-hex-to-theme.md) - Replace arbitrary hex colors with theme tokens 82 - [`arb-spacing-to-scale`](references/arb-spacing-to-scale.md) - Replace arbitrary spacing with theme scale 83 - [`arb-dynamic-classes`](references/arb-dynamic-classes.md) - Avoid dynamic class name construction 84 - [`arb-breakpoint-to-theme`](references/arb-breakpoint-to-theme.md) - Replace arbitrary breakpoints with @theme 85 - [`arb-zindex-to-scale`](references/arb-zindex-to-scale.md) - Replace arbitrary z-index with defined scale 86 87 ### 6. Syntax Modernization (MEDIUM) 88 89 - [`syntax-css-variable-parens`](references/syntax-css-variable-parens.md) - Update CSS variable syntax from brackets to parentheses 90 - [`syntax-variant-stacking`](references/syntax-variant-stacking.md) - Update variant stacking to left-to-right order 91 - [`syntax-important-modifier`](references/syntax-important-modifier.md) - Use trailing ! for important modifier 92 - [`syntax-grid-arbitrary`](references/syntax-grid-arbitrary.md) - Use underscores in grid arbitrary values 93 - [`syntax-gradient-preservation`](references/syntax-gradient-preservation.md) - Reset gradient stops explicitly in variants 94 - [`syntax-hover-media-query`](references/syntax-hover-media-query.md) - Account for hover variant media query wrapping 95 96 ### 7. @apply & Architecture Cleanup (MEDIUM) 97 98 - [`arch-apply-to-component`](references/arch-apply-to-component.md) - Extract @apply blocks into framework components 99 - [`arch-layer-to-utility`](references/arch-layer-to-utility.md) - Replace @layer components with @utility 100 - [`arch-scoped-reference`](references/arch-scoped-reference.md) - Use @reference for @apply in scoped styles 101 - [`arch-safelist-to-source`](references/arch-safelist-to-source.md) - Replace safelist with @source inline() 102 - [`arch-domain-composition`](references/arch-domain-composition.md) - Reserve Tailwind for primitives, compose for domain 103 104 ### 8. Modern Feature Adoption (LOW-MEDIUM) 105 106 - [`adopt-container-queries`](references/adopt-container-queries.md) - Use container queries instead of viewport breakpoints 107 - [`adopt-not-variant`](references/adopt-not-variant.md) - Use not-* variant for negated conditions 108 - [`adopt-in-variant`](references/adopt-in-variant.md) - Use in-* variant to simplify parent-state styling 109 - [`adopt-field-sizing`](references/adopt-field-sizing.md) - Use field-sizing-content for auto-resizing textareas 110 - [`adopt-starting-variant`](references/adopt-starting-variant.md) - Use starting variant for entry animations without JS 111 112 ## How to Use 113 114 Read individual reference files for detailed explanations and code examples: 115 116 - [Section definitions](references/_sections.md) - Category structure and impact levels 117 - [Rule template](assets/templates/_template.md) - Template for adding new rules 118 119 ## Reference Files 120 121 | File | Description | 122 |------|-------------| 123 | [references/_sections.md](references/_sections.md) | Category definitions and ordering | 124 | [assets/templates/_template.md](assets/templates/_template.md) | Template for new rules | 125 | [metadata.json](metadata.json) | Version and reference information |
ComeOnOliver/skillshub/tree/main/skills/pproenca/dot-skills/tailwind-refactor commit 02ee9fade0
Frequently asked questions How do I install the Tailwind Refactor skill? Run npx skillmds@latest add comeonoliver/tailwind-refactor in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
What does the Tailwind Refactor skill do? Community Tailwind CSS Refactoring Best Practices It is listed under Web & Frontend on SkillMD.
Is Tailwind Refactor safe to use? This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
Which AI agents work with Tailwind Refactor? This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Is Tailwind Refactor free to use? Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Who published Tailwind Refactor? ComeOnOliver (@comeonoliver) published this skill. Their other Agent Skills are listed on their SkillMD profile.