Skip to main content
skill CX Codex

converting-css-modules-to-tailwind — Claude Code skill: CSS Modules

Moves one component off CSS Modules and onto Tailwind utility classes, then removes the module file and its import.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add spencerpauly/awesome-cursor-skills --skill converting-css-modules-to-tailwind -a claude-code
Open on GitHub

What converting-css-modules-to-tailwind does

The skill reads a component and its .module.css or .module.scss, maps every styles.xxx reference to the CSS rule behind it, and swaps it for Tailwind utilities. It also covers the patterns that usually stall a migration: composes, conditional className calls through clsx, dynamic class selection, and :global(...) overrides. For dynamic variants it suggests a lookup object such as variantClasses[variant] instead of building a class name from a string.

Cleanup is part of the workflow. The skill drops the module import line, deletes the .module.css or .module.scss file, and searches the codebase for other imports of it. SCSS nesting gets flattened into utilities on each element, $variables are meant to move into tailwind.config.ts theme values, and mixins turn into utility composition or a separate component. Pseudo-elements that carry content need before: or after: prefixes plus a content-['...'] value.

It converts one component at a time and will not batch a whole directory. Where Tailwind has no matching variant for :nth-child or :first-of-type, it keeps a minimal CSS rule rather than forcing a rewrite. It also refuses to recreate the module as @apply classes, because the point of the migration is to remove that indirection.

What it helps with

  • convert a component from .module.css to Tailwind classes
  • flatten composes into a single set of utilities
  • replace styles[variant] with a variant lookup object
  • move :global(...) rules into the global stylesheet
  • delete the module file and catch leftover imports

Example prompts for the agent

  • convert Card.module.css to Tailwind, component is Card.tsx
  • strip styles.xxx from Button.tsx and delete the module
  • flatten composes in Button.module.scss into utilities

How to install converting-css-modules-to-tailwind

1Skills CLI (Vercel)

npx skills add spencerpauly/awesome-cursor-skills --skill converting-css-modules-to-tailwind -a claude-code

2Manually: put the files in place

~/.claude/skills/converting-css-modules-to-tailwind/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/converting-css-modules-to-tailwind/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about converting-css-modules-to-tailwind

How do I install converting-css-modules-to-tailwind in Claude?

Run npx skills add spencerpauly/awesome-cursor-skills --skill converting-css-modules-to-tailwind -a claude-code. The skill lands at ~/.claude/skills/converting-css-modules-to-tailwind/SKILL.md.

What does converting-css-modules-to-tailwind do?

It migrates a component from CSS Modules to Tailwind utility classes. It also removes the module import, deletes the file, and checks whether anything else still imports it.

How does it handle :nth-child and pseudo-elements?

For :nth-child and :first-of-type it looks for a matching Tailwind variant and keeps a minimal CSS rule when there is none. Pseudo-elements with content need before: or after: prefixes and a content-['...'] value.

Source text

SKILL.md · CC0-1.0
---
name: converting-css-modules-to-tailwind
description: Migrate CSS Modules (.module.css/.module.scss) to Tailwind utility classes. Handles styles object removal, className interpolation, composition, and global overrides.
user-invocable: true
---

# Converting CSS Modules to Tailwind

Migrate a component from CSS Modules (`.module.css` / `.module.scss`) to Tailwind utility classes.

## Workflow

### 1. Inventory the Module

Read the `.module.css` file and the component that imports it. Map every `styles.xxx` reference to the CSS rule it resolves to.

```tsx
// Before
import styles from './Card.module.css';
<div className={styles.card}>
  <h2 className={styles.title}>{title}</h2>
  <p className={styles.body}>{children}</p>
</div>
```

```css
/* Card.module.css */
.card { display: flex; flex-direction: column; gap: 16px; padding: 24px; border-radius: 12px; background: white; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.title { font-size: 20px; font-weight: 600; color: #111827; }
.body { font-size: 14px; color: #6b7280; line-height: 1.6; }
```

### 2. Convert Each Class

Replace `styles.xxx` with equivalent Tailwind utilities:

```tsx
// After
<div className="flex flex-col gap-4 p-6 rounded-xl bg-white shadow-sm">
  <h2 className="text-xl font-semibold text-gray-900">{title}</h2>
  <p className="text-sm text-gray-500 leading-relaxed">{children}</p>
</div>
```

### 3. Handle CSS Modules Patterns

**`composes` keyword:**
```css
.base { padding: 8px 16px; border-radius: 4px; }
.primary { composes: base; background: blue; color: white; }
```
→ Flatten into a single set of utilities. If reuse is needed, extract a component, not a class.

**Conditional classNames with `clsx`/`classnames`:**
```tsx
// Before
className={clsx(styles.button, isActive && styles.active)}
// After
className={clsx("px-4 py-2 rounded", isActive && "bg-blue-600 text-white")}
```

**Dynamic class selection:**
```tsx
// Before
className={styles[variant]}
// After — use a lookup object
const variantClasses = {
  primary: "bg-blue-600 text-white hover:bg-blue-700",
  secondary: "bg-gray-100 text-gray-900 hover:bg-gray-200",
  danger: "bg-red-600 text-white hover:bg-red-700",
};
className={variantClasses[variant]}
```

**CSS Modules global overrides:**
```css
:global(.some-library-class) { ... }
```
→ Move to `globals.css` with `@layer components { }` or use Tailwind's `@apply` in the global stylesheet.

**SCSS features (nesting, variables, mixins):**
- Nested selectors → flatten into utility classes on each element
- SCSS `$variables` → map to `tailwind.config.ts` theme values
- Mixins → replace with utility composition or extract components

### 4. Clean Up

1. Remove the `import styles from './Xxx.module.css'` line
2. Delete the `.module.css` / `.module.scss` file
3. If the component had a co-located `index.ts` barrel that re-exported styles, update it
4. Search the codebase for any other imports of the deleted module
5. Run the app and verify visually — check for regressions

## Rules

- Convert one component at a time — don't batch entire directories
- Keep conditional logic in `clsx()` or template literals, not in CSS
- If a module has pseudo-element styles (`:before`, `:after` with `content`), those need `before:` / `after:` prefixes plus `content-['...']` in Tailwind
- For `:nth-child`, `:first-of-type`, etc. — check if Tailwind has a matching variant, otherwise keep a minimal CSS rule
- Don't create `@apply` classes to replicate what the module did — the goal is to eliminate the indirection

© spencerpauly · CC0-1.0 · spencerpauly/awesome-cursor-skills

Similar skills

Everything for Frontend and UI →

From the same set60

updating-npm-package Updates npm dependencies safely by checking npmjs.com and adapting to the version jump. It runs tests on minor updates and finds migration guides for major ones. CX Codex +1 398installs react-native-patterns This skill guides an agent building React Native and Expo apps, covering navigation, platform-specific code, styling, lists, and native modules. CX Codex +1 399installs adding-docker This skill writes a Dockerfile, docker-compose setup and .dockerignore for your app. Useful when you want a container without hand-writing the configs. CX Codex +1 398installs fixing-broken-links This skill scans project files for dead URLs and broken local paths, verifies responses with curl, and repairs or removes missing links. CX Codex +1 393installs generating-images This skill generates and edits images through the OpenAI Image API on gpt-image-2. Handy when you need an OG banner, an icon or a mockup without leaving the agent chat. CX Codex +1 388installs adding-error-tracking This skill wires Sentry into a web app: error tracking, performance traces and source maps. Useful when you want crash reporting without hand-rolling the config. CX Codex +1 386installs tailing-build-output Monitors build output in real time, catches errors as they stream, and patches source files before Webpack, Turbo, or Docker finishes. CX Codex +1 384installs comparing-branches-visually Checks out two branches in separate worktrees, runs both dev servers on different ports, screenshots the same pages and reports before/after. CX Codex +1 383installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor