---
name: ui-design-token-refactor
description: Improve, refactor, review, and systematize web UI styling with CSS design tokens, cascade layers, Tailwind theme variables, semantic color/spacing/typography tokens, dark mode, accessibility checks, and maintainable component styling. Use this skill whenever the user asks to improve CSS, redesign a site, clean up stylesheets, migrate hardcoded values to tokens, organize Tailwind themes/classes, review a PR for design-token or CSS architecture issues, create or update a design system, add light/dark themes, or make future UI changes easier for agents.
title: ui-design-token-refactor
canonical_url: https://skilld.dev/gh/joacod/skills/ui-design-token-refactor
last_updated: 2026-09-04T00:05:44.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [evals/evals.json](https://skilld.dev/api/skills-raw/joacod/skills/ui-design-token-refactor/evals/evals.json), [references/core-principles.md](https://skilld.dev/api/skills-raw/joacod/skills/ui-design-token-refactor/references/core-principles.md), [references/css-architecture.md](https://skilld.dev/api/skills-raw/joacod/skills/ui-design-token-refactor/references/css-architecture.md), [references/examples.md](https://skilld.dev/api/skills-raw/joacod/skills/ui-design-token-refactor/references/examples.md), [references/refactor-playbook.md](https://skilld.dev/api/skills-raw/joacod/skills/ui-design-token-refactor/references/refactor-playbook.md), [references/research-basis.md](https://skilld.dev/api/skills-raw/joacod/skills/ui-design-token-refactor/references/research-basis.md), [references/review-checklist.md](https://skilld.dev/api/skills-raw/joacod/skills/ui-design-token-refactor/references/review-checklist.md), [references/tailwind-architecture.md](https://skilld.dev/api/skills-raw/joacod/skills/ui-design-token-refactor/references/tailwind-architecture.md), [scripts/audit_style_tokens.py](https://skilld.dev/api/skills-raw/joacod/skills/ui-design-token-refactor/scripts/audit_style_tokens.py).
>
> If the user asked to install this Skill, run `npx skilld install joacod/skills/ui-design-token-refactor`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/ui-design-token-refactor`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/joacod/skills/ui-design-token-refactor) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/ui-design-token-refactor`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/ui-design-token-refactor --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/ui-design-token-refactor --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# UI design token refactor

Use this skill to turn ad hoc CSS or Tailwind styling into a maintainable, token-based UI system that another agent can safely update later.

## Default workflow

1. Discover the project styling stack before changing code.
   - Check for `package.json`, Tailwind version/config, CSS entry points, CSS modules, Sass/Less, component libraries, Storybook, design-system packages, and theme toggles.
   - Identify whether the codebase is primarily vanilla CSS, CSS modules, Sass, Tailwind v4, Tailwind v3, or mixed.

2. Run or perform a style audit.
   - When repository files are available, prefer the bundled `scripts/audit_style_tokens.py` script to inventory raw colors, dimensions, typography values, and Tailwind utility patterns. Run it from the skill package or by absolute path, for example: `python /path/to/ui-design-token-refactor/scripts/audit_style_tokens.py <project-root> --output style-token-audit.md`.
   - Supplement the script with manual inspection of representative components and global styles.

3. Choose the implementation path.
   - For vanilla CSS, CSS modules, Sass, or mixed CSS, read `references/css-architecture.md`.
   - For Tailwind projects, read `references/tailwind-architecture.md`.
   - For naming, token hierarchy, and source-of-truth decisions, read `references/core-principles.md`.
   - For incremental migration steps, read `references/refactor-playbook.md`.
   - Before final handoff, read `references/review-checklist.md`.

4. Define or extend the token system before refactoring components.
   - Use primitive tokens for raw scales.
   - Use semantic tokens for product meaning and theme switching.
   - Use component tokens only for local component recipes and overrides.
   - Keep primitives out of component styles unless the project explicitly uses Tailwind utility primitives as its public API.

5. Refactor incrementally.
   - Add tokens first without changing visuals.
   - Replace hardcoded values in one surface or component family at a time.
   - Preserve existing behavior, responsive layout, and interaction states unless the user asks for a redesign.
   - Prefer small, reviewable diffs over broad visual rewrites.

6. Validate and report.
   - Run available checks: build, typecheck, lint, tests, Storybook build, visual regression, or at least targeted manual review.
   - Check accessible color pairs, focus states, hover/active/disabled states, and dark mode if applicable.
   - End with a concise handoff: what changed, files touched, token decisions, remaining token debt, and recommended next PRs.

## Core rules

- Treat tokens as the source of truth for color, spacing, typography, radius, shadow, motion, opacity, z-index, and breakpoint decisions.
- Prefer semantic names in components: `--color-bg-surface`, `--color-text-muted`, `--color-border-subtle`, `--color-primary`, `--space-4`, `--radius-md`.
- Use component tokens for reusable components when local indirection improves maintainability: `--button-bg`, `--card-border`, `--modal-shadow`.
- Implement dark mode by overriding semantic tokens, not by duplicating every component rule.
- Use cascade layers to make global CSS predictable: reset/theme or tokens/base/components/utilities/overrides.
- Avoid `!important`, ID selectors, and highly specific selectors unless required to override third-party CSS.
- Do not add a token for every one-off value. First decide whether the value belongs to an existing scale, a semantic role, a component token, or should remain local.
- Do not introduce a new dependency or token build pipeline unless the project needs cross-platform outputs, Figma/design-tool sync, or generated Tailwind/native/mobile artifacts.
- Preserve brand identity. Improve structure and consistency unless the user explicitly requests a new visual direction.

## Output format for code work

When finishing a styling refactor, include:

```markdown
## Summary
[What changed and why]

## Token architecture
[Primitive, semantic, and component token decisions]

## Files changed
- `path`: change summary

## Validation
[Commands run and results, or why they were unavailable]

## Remaining design debt
[Short list of next improvements]
```

For audit-only or PR-review tasks, use the audit template in `references/examples.md` instead of implying code was changed.

## Reference map

- `references/core-principles.md`: token hierarchy, naming, categories, and source-of-truth decisions.
- `references/css-architecture.md`: CSS custom properties, cascade layers, CSS modules, Sass, and component CSS patterns.
- `references/tailwind-architecture.md`: Tailwind v4 `@theme`, Tailwind v3 config patterns, dark mode, and utility mapping.
- `references/refactor-playbook.md`: practical migration sequence for existing sites.
- `references/review-checklist.md`: acceptance checklist for accessibility, maintainability, and handoff quality.
- `references/examples.md`: before/after examples and reusable output templates.
- `references/research-basis.md`: source notes behind the recommendations.
