---
name: styling-system
description: "Load PROACTIVELY when task involves CSS architecture, theming, or visual design systems. Use when user says \"set up Tailwind\", \"add dark mode\", \"create a design system\", \"make it responsive\", or \"configure the theme\". Covers Tailwind configuration and custom plugins, design token systems, responsive breakpoint strategies, dark mode implementation, component variant patterns (CVA/class-variance-authority), CSS-in-JS alternatives, and animation patterns."
metadata:
version: 1.0.0
category: outcome
tags: [css, tailwind, styling, theme, dark-mode, responsive, design-tokens]
---
## Resources
```
scripts/
validate-styling.sh
references/
styling-comparison.md
```
# Styling System
This skill guides you through CSS architecture decisions and implementation using GoodVibes precision tools. Use this workflow when setting up styling infrastructure, creating design systems, or implementing theming and responsive patterns.
## When to Use This Skill
Load this skill when:
- Setting up a new project's styling infrastructure
- Choosing between Tailwind, CSS Modules, CSS-in-JS, or vanilla CSS
- Implementing a design token system
- Adding dark mode support
- Creating responsive layouts and breakpoint strategies
- Migrating between styling approaches
- Building component variant systems
- Setting up animation patterns
Trigger phrases: "setup styling", "add Tailwind", "implement dark mode", "design tokens", "responsive design", "CSS architecture", "theme system".
## Core Workflow
### Phase 1: Discovery
Before making styling decisions, understand the project's current state.
#### Step 1.1: Detect Existing Styling Approach
Use `discover` to find styling patterns across the codebase.
```yaml
discover:
queries:
- id: tailwind_usage
type: grep
pattern: "(className=|class=).*\".*\\b(flex|grid|text-|bg-|p-|m-)"
glob: "**/*.{tsx,jsx,vue,svelte}"
- id: css_modules
type: glob
patterns: ["**/*.module.css", "**/*.module.scss"]
- id: css_in_js
type: grep
pattern: "(styled\\.|styled\\(|css`|makeStyles|createStyles)"
glob: "**/*.{ts,tsx,js,jsx}"
- id: design_tokens
type: glob
patterns: ["**/tokens.{ts,js,json}", "**/design-tokens.{ts,js,json}", "**/theme.{ts,js}"]
- id: dark_mode
type: grep
pattern: "(dark:|data-theme|ThemeProvider|useTheme|darkMode)"
glob: "**/*.{ts,tsx,js,jsx,css,scss}"
verbosity: count_only
```
**What this reveals:**
- Primary styling approach (Tailwind, CSS Modules, CSS-in-JS, vanilla)
- Whether design tokens exist
- Dark mode implementation status
- Consistency across the codebase
#### Step 1.2: Check Configuration Files
Read existing config to understand the setup.
```yaml
precision_read:
files:
- path: "tailwind.config.js"
extract: content
- path: "tailwind.config.ts"
extract: content
- path: "postcss.config.js"
extract: content
- path: "src/styles/globals.css"
extract: outline
verbosity: minimal
```
#### Step 1.3: Analyze Component Styling Patterns
Read representative components to understand conventions.
```yaml
precision_read:
files:
- path: "src/components/Button.tsx" # or discovered component
extract: content
- path: "src/components/Card.tsx"
extract: content
output:
max_per_item: 100
verbosity: standard
```
### Phase 2: Decision Making
Choose the styling approach that fits your project needs. See `references/styling-comparison.md` for the complete decision tree.
#### Quick Decision Guide
**Use Tailwind CSS when:**
- You want rapid prototyping with utility classes
- Consistency across team is a priority
- You prefer design constraints over complete freedom
- You're building component-based UIs (React, Vue, Svelte)
**Use CSS Modules when:**
- You want scoped styles without build complexity
- You prefer writing traditional CSS
- You need coexistence with existing global styles
- Bundle size is a major concern (smaller than Tailwind)
**Use CSS-in-JS when:**
- You need runtime dynamic theming
- You want TypeScript types for style props
- Component-scoped styles with JS logic are required
- You're using styled-components or Emotion
**Use Vanilla CSS when:**
- You're building simple sites with minimal interactivity
- You want maximum control and minimal dependencies
- Progressive enhancement is critical
- You prefer cascade and inheritance patterns
For detailed framework-specific patterns, see `references/styling-comparison.md`.
### Phase 3: Configuration Setup
#### Step 3.1: Install Dependencies
Based on your chosen approach, install required packages.
**Tailwind CSS:**
```yaml
precision_exec:
commands:
- cmd: "npm install -D tailwindcss postcss autoprefixer"
expect:
exit_code: 0
- cmd: "npx tailwindcss init -p"
expect:
exit_code: 0
verbosity: minimal
```
**CSS-in-JS (styled-components):**
```yaml
precision_exec:
commands:
- cmd: "npm install styled-components"
- cmd: "npm install -D @types/styled-components"
verbosity: minimal
```
#### Step 3.2: Create Configuration
Write config files following best practices.
**Tailwind Config Example:**
```typescript
import type { Config } from 'tailwindcss';
const config: Config = {
content: [
'./src/pages/**/*.{js,ts,jsx,tsx,mdx}',
'./src/components/**/*.{js,ts,jsx,tsx,mdx}',
'./src/app/**/*.{js,ts,jsx,tsx,mdx}',
],
darkMode: 'class', // or 'media' for system preference
theme: {
extend: {
colors: {
primary: {
50: '#f0f9ff',
100: '#e0f2fe',
// ... full scale
900: '#0c4a6e',
},
},
fontFamily: {
sans: ['var(--font-inter)', 'system-ui', 'sans-serif'],
},
spacing: {
'18': '4.5rem',
},
},
},
plugins: [],
};
export default config;
```
**Best Practices:**
- Use TypeScript for config files (type safety)
- Extend theme, don't replace defaults
- Use CSS variables for dynamic values
- Keep content paths specific to avoid slow builds
- Use the `class` strategy for dark mode (more control)
#### Step 3.3: Write Configuration Files
```yaml
precision_write:
files:
- path: "tailwind.config.ts"
content: |
import type { Config } from 'tailwindcss';
// ... [full config]
- path: "src/styles/globals.css"
content: |
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
/* ... design tokens */
}
.dark {
--background: 222.2 84% 4.9%;
--foreground: 210 40% 98%;
}
}
verbosity: count_only
```
### Phase 4: Design Token System
#### Step 4.1: Define Token Structure
Create a centralized token system for consistency.
**Token Categories:**
- **Colors**: Primary, secondary, neutral, semantic (success, error, warning)
- **Typography**: Font families, sizes, weights, line heights
- **Spacing**: Consistent scale (4px base, 8px increments)
- **Shadows**: Elevation system
- **Borders**: Radii, widths
- **Breakpoints**: Responsive design system
- **Animation**: Duration, easing functions
**Implementation Pattern:**
```typescript
// src/styles/tokens.ts
export const tokens = {
colors: {
primary: {
light: '#3b82f6',
DEFAULT: '#2563eb',
dark: '#1d4ed8',
},
semantic: {
success: '#10b981',
error: '#ef4444',
warning: '#f59e0b',
},
},
spacing: {
xs: '0.25rem', // 4px
sm: '0.5rem', // 8px
md: '1rem', // 16px
lg: '1.5rem', // 24px
xl: '2rem', // 32px
},
typography: {
fontFamily: {
sans: ['Inter', 'system-ui', 'sans-serif'],
mono: ['Fira Code', 'monospace'],
},
fontSize: {
xs: ['0.75rem', { lineHeight: '1rem' }],
sm: ['0.875rem', { lineHeight: '1.25rem' }],
base: ['1rem', { lineHeight: '1.5rem' }],
lg: ['1.125rem', { lineHeight: '1.75rem' }],
xl: ['1.25rem', { lineHeight: '1.75rem' }],
},
},
} as const;
export type Tokens = typeof tokens;
// Integration with ThemeProvider (React Context)
type Theme = {
tokens: Tokens;
mode: 'light' | 'dark';
};
// Integration with styled-components
import 'styled-components';
declare module 'styled-components' {
export interface DefaultTheme extends Tokens {
mode: 'light' | 'dark';
}
}
// Usage in components
import { useTheme } from 'styled-components';
const Button = styled.button`
background: ${props => props.theme.colors.primary};
padding: ${props => props.theme.spacing[4]};
`;
```
#### Step 4.2: Integrate Tokens with Tailwind
```typescript
// tailwind.config.ts
import { tokens } from './src/styles/tokens';
const config: Config = {
theme: {
extend: {
colors: tokens.colors,
spacing: tokens.spacing,
fontFamily: tokens.typography.fontFamily,
fontSize: tokens.typography.fontSize,
},
},
};
```
### Phase 5: Dark Mode Implementation
#### Step 5.1: Choose Dark Mode Strategy
**Class-based (Recommended):**
- More control over toggle behavior
- Can persist user preference
- Works with next-themes or similar libraries
**Media query-based:**
- Respects system preference only
- No JS required
- Less flexibility
#### Step 5.2: Setup next-themes (React/Next.js)
```typescript
// src/components/ThemeProvider.tsx
import { ThemeProvider as NextThemesProvider } from 'next-themes';
import type { ReactNode } from 'react';
interface ThemeProviderProps {
children: ReactNode;
}
export function ThemeProvider({ children }: ThemeProviderProps) {
return (
{error}
)}