Frontend Styling
Guidance for debugging layout issues, ensuring style consistency, and applying best practices in frontend development, with emphasis on Svelte/SvelteKit projects.
Detailed material loads on demand:
- Step-by-step layout debugging, the style-consistency workflow, and the accessibility/debugging checklists: workflows-and-checklists.md
- Svelte-specific styling, common flexbox/grid patterns, and anti-patterns: svelte-and-patterns.md
When This Skill Applies
Use this skill when:
- Fixing layout problems (alignment, spacing, positioning, responsive issues)
- Unifying component styling to match project conventions
- Debugging visual inconsistencies or CSS bugs
- Implementing new UI components
- Refactoring styling approaches
- Questions about CSS organization or best practices
Core Principles
1. Accessibility First
Accessibility is not a polish step; it's a structural requirement. Every styling decision should pass the accessibility check before considering aesthetics.
Non-negotiable:
- Colour contrast meets WCAG 2.1 AA (4.5:1 normal text, 3:1 large text)
- Focus indicators visible on all interactive elements
- No information conveyed by colour alone (use icons, text, patterns too)
- Reduced motion support via
prefers-reduced-motion
- Touch targets at least 44×44px on mobile
- Text remains readable at 200% zoom
/* Always include focus styles */
:focus-visible {
outline: 2px solid var(--color-focus);
outline-offset: 2px;
}
/* Respect motion preferences */
@media (prefers-reduced-motion: reduce) {
* {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
}
}
/* Never rely on colour alone */
.error-field {
border-color: var(--color-error);
border-width: 2px; /* Visual indicator beyond colour */
}
.error-message {
color: var(--color-error);
}
.error-message::before {
content: "⚠ "; /* Icon reinforces the colour */
}
The full pre-ship checklist is in workflows-and-checklists.md.
2. Plan Before Execute
For non-trivial styling changes:
- Analyse - Understand the current implementation
- Plan - Outline proposed changes in logical order
- Confirm - Get user approval before execution
- Execute - Apply changes methodically
3. Consistency Over Cleverness
- Match the project's established patterns
- Don't introduce new approaches without discussion
- Preserve existing styling architecture
- Keep component styles predictable
4. Hierarchy and Order
When fixing multiple issues:
- Fix parent containers before children
- Address layout structure before fine-tuning
- Edit CSS files before component files when possible
- Work through child components before parent components
Project Preferences
Naming Conventions
- CSS classes:
kebab-case (e.g., card-header, btn-primary)
- Component files:
PascalCase.svelte (e.g., UserCard.svelte)
- BEM-like modifiers: Double dash for variants (e.g.,
btn--primary, card--elevated)
Spacing and Units
- Use
rem for spacing (0.25rem, 0.5rem, 1rem, 1.5rem, 2rem)
- Use
em for typography-relative spacing
- Avoid magic numbers - prefer CSS variables
Color Management
- Define colors as CSS variables in root/theme
- Never hard-code hex/rgb values in components
- Use semantic naming (
--color-primary, not --blue-500)
- The project's theme (
.claude/themes/<family>-html.json, see ~/.claude/library/references/theme-conventions.md) is the palette; emit its tokens with bun ~/.claude/library/scripts/theme/emit.ts <file> -o src/lib/styles/tokens.css rather than typing hex values. No theme yet: run /theme-factory "html" first.
- The emitted block defines
--ink, --ink-muted, --surface, --surface-raised, --line, --accent, --accent-ink, --accent-2, --ok, --warn, --danger, --info plus type and shape tokens, light and dark. Components alias those to roles; nothing references a hex:
:root {
/* Roles on top of the theme tokens */
--color-primary: var(--accent);
--color-on-primary: var(--accent-ink);
--color-danger: var(--danger);
--color-surface: var(--surface);
--color-on-surface: var(--ink);
}
Responsive Design
- Mobile-first approach (min-width media queries)
- Common breakpoints:
sm: 640px
md: 768px
lg: 1024px
xl: 1280px
Permission and Confirmation
Always ask permission before:
- Editing multiple files (confirm per file or batch)
- Making structural changes to component architecture
- Introducing new styling patterns or conventions
- Making changes that affect parent/sibling components
Always explain:
- Why a particular approach is recommended
- What knock-on effects changes might have
- Which order changes will be applied
- Alternative approaches if multiple options exist
Success Criteria
A styling task is complete when:
- Visual issues are resolved across all target breakpoints
- Styling matches project conventions consistently
- No new bugs or regressions introduced
- Code is maintainable and follows project patterns
- User has confirmed the solution meets requirements
- Accessibility checklist passes (contrast, focus, keyboard, screen reader)
- Animations respect
prefers-reduced-motion
1---2name: role-frontend-styler3description: Frontend styling: layout debugging, style consistency, CSS best practices for Svelte/SvelteKit.4---56# Frontend Styling78Guidance for debugging layout issues, ensuring style consistency, and applying best practices in frontend development, with emphasis on Svelte/SvelteKit projects.910**Detailed material loads on demand:**11- Step-by-step layout debugging, the style-consistency workflow, and the accessibility/debugging checklists: [workflows-and-checklists.md](workflows-and-checklists.md)12- Svelte-specific styling, common flexbox/grid patterns, and anti-patterns: [svelte-and-patterns.md](svelte-and-patterns.md)1314---1516## When This Skill Applies1718Use this skill when:19- Fixing layout problems (alignment, spacing, positioning, responsive issues)20- Unifying component styling to match project conventions21- Debugging visual inconsistencies or CSS bugs22- Implementing new UI components23- Refactoring styling approaches24- Questions about CSS organization or best practices2526---2728## Core Principles2930### 1. Accessibility First31Accessibility is not a polish step; it's a structural requirement. Every styling decision should pass the accessibility check before considering aesthetics.3233**Non-negotiable**:34- Colour contrast meets WCAG 2.1 AA (4.5:1 normal text, 3:1 large text)35- Focus indicators visible on all interactive elements36- No information conveyed by colour alone (use icons, text, patterns too)37- Reduced motion support via `prefers-reduced-motion`38- Touch targets at least 44×44px on mobile39- Text remains readable at 200% zoom4041```css42/* Always include focus styles */43:focus-visible {44 outline: 2px solid var(--color-focus);45 outline-offset: 2px;46}4748/* Respect motion preferences */49@media (prefers-reduced-motion: reduce) {50 * {51 animation-duration: 0.01ms !important;52 transition-duration: 0.01ms !important;53 }54}5556/* Never rely on colour alone */57.error-field {58 border-color: var(--color-error);59 border-width: 2px; /* Visual indicator beyond colour */60}61.error-message {62 color: var(--color-error);63}64.error-message::before {65 content: "⚠ "; /* Icon reinforces the colour */66}67```6869The full pre-ship checklist is in [workflows-and-checklists.md](workflows-and-checklists.md).7071### 2. Plan Before Execute72For non-trivial styling changes:731. **Analyse** - Understand the current implementation742. **Plan** - Outline proposed changes in logical order753. **Confirm** - Get user approval before execution764. **Execute** - Apply changes methodically7778### 3. Consistency Over Cleverness79- Match the project's established patterns80- Don't introduce new approaches without discussion81- Preserve existing styling architecture82- Keep component styles predictable8384### 4. Hierarchy and Order85When fixing multiple issues:861. Fix parent containers before children872. Address layout structure before fine-tuning883. Edit CSS files before component files when possible894. Work through child components before parent components9091---9293## Project Preferences9495### Naming Conventions96- **CSS classes**: `kebab-case` (e.g., `card-header`, `btn-primary`)97- **Component files**: `PascalCase.svelte` (e.g., `UserCard.svelte`)98- **BEM-like modifiers**: Double dash for variants (e.g., `btn--primary`, `card--elevated`)99100### Spacing and Units101- Use `rem` for spacing (0.25rem, 0.5rem, 1rem, 1.5rem, 2rem)102- Use `em` for typography-relative spacing103- Avoid magic numbers - prefer CSS variables104105### Color Management106- Define colors as CSS variables in root/theme107- Never hard-code hex/rgb values in components108- Use semantic naming (`--color-primary`, not `--blue-500`)109- The project's theme (`.claude/themes/<family>-html.json`, see `~/.claude/library/references/theme-conventions.md`) is the palette; emit its tokens with `bun ~/.claude/library/scripts/theme/emit.ts <file> -o src/lib/styles/tokens.css` rather than typing hex values. No theme yet: run `/theme-factory "html"` first.110- The emitted block defines `--ink`, `--ink-muted`, `--surface`, `--surface-raised`, `--line`, `--accent`, `--accent-ink`, `--accent-2`, `--ok`, `--warn`, `--danger`, `--info` plus type and shape tokens, light and dark. Components alias those to roles; nothing references a hex:111112```css113:root {114 /* Roles on top of the theme tokens */115 --color-primary: var(--accent);116 --color-on-primary: var(--accent-ink);117 --color-danger: var(--danger);118 --color-surface: var(--surface);119 --color-on-surface: var(--ink);120}121```122123### Responsive Design124- Mobile-first approach (min-width media queries)125- Common breakpoints:126 - `sm`: 640px127 - `md`: 768px128 - `lg`: 1024px129 - `xl`: 1280px130131---132133## Permission and Confirmation134135**Always ask permission before:**136- Editing multiple files (confirm per file or batch)137- Making structural changes to component architecture138- Introducing new styling patterns or conventions139- Making changes that affect parent/sibling components140141**Always explain:**142- Why a particular approach is recommended143- What knock-on effects changes might have144- Which order changes will be applied145- Alternative approaches if multiple options exist146147---148149## Success Criteria150151A styling task is complete when:152- Visual issues are resolved across all target breakpoints153- Styling matches project conventions consistently154- No new bugs or regressions introduced155- Code is maintainable and follows project patterns156- User has confirmed the solution meets requirements157- Accessibility checklist passes (contrast, focus, keyboard, screen reader)158- Animations respect `prefers-reduced-motion`