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."4when_to_use: "When a layout is broken, styles are inconsistent across components or CSS needs a best-practice review; auto-loads only when work touches .svelte or .css files."5user-invocable: false6metadata:7 family: clod-role8paths:9 - "**/*.svelte"10 - "**/*.css"11allowed-tools:12 - Read13 - Glob14 - Grep15---1617# Frontend Styling1819Guidance for debugging layout issues, ensuring style consistency, and applying best practices in frontend development, with emphasis on Svelte/SvelteKit projects.2021**Detailed material loads on demand:**22- Step-by-step layout debugging, the style-consistency workflow, and the accessibility/debugging checklists: [workflows-and-checklists.md](workflows-and-checklists.md)23- Svelte-specific styling, common flexbox/grid patterns, and anti-patterns: [svelte-and-patterns.md](svelte-and-patterns.md)2425---2627## When This Skill Applies2829Use this skill when:30- Fixing layout problems (alignment, spacing, positioning, responsive issues)31- Unifying component styling to match project conventions32- Debugging visual inconsistencies or CSS bugs33- Implementing new UI components34- Refactoring styling approaches35- Questions about CSS organization or best practices3637---3839## Core Principles4041### 1. Accessibility First42Accessibility is not a polish step; it's a structural requirement. Every styling decision should pass the accessibility check before considering aesthetics.4344**Non-negotiable**:45- Colour contrast meets WCAG 2.1 AA (4.5:1 normal text, 3:1 large text)46- Focus indicators visible on all interactive elements47- No information conveyed by colour alone (use icons, text, patterns too)48- Reduced motion support via `prefers-reduced-motion`49- Touch targets at least 44×44px on mobile50- Text remains readable at 200% zoom5152```css53/* Always include focus styles */54:focus-visible {55 outline: 2px solid var(--color-focus);56 outline-offset: 2px;57}5859/* Respect motion preferences */60@media (prefers-reduced-motion: reduce) {61 * {62 animation-duration: 0.01ms !important;63 transition-duration: 0.01ms !important;64 }65}6667/* Never rely on colour alone */68.error-field {69 border-color: var(--color-error);70 border-width: 2px; /* Visual indicator beyond colour */71}72.error-message {73 color: var(--color-error);74}75.error-message::before {76 content: "⚠ "; /* Icon reinforces the colour */77}78```7980The full pre-ship checklist is in [workflows-and-checklists.md](workflows-and-checklists.md).8182### 2. Plan Before Execute83For non-trivial styling changes:841. **Analyse** - Understand the current implementation852. **Plan** - Outline proposed changes in logical order863. **Confirm** - Get user approval before execution874. **Execute** - Apply changes methodically8889### 3. Consistency Over Cleverness90- Match the project's established patterns91- Don't introduce new approaches without discussion92- Preserve existing styling architecture93- Keep component styles predictable9495### 4. Hierarchy and Order96When fixing multiple issues:971. Fix parent containers before children982. Address layout structure before fine-tuning993. Edit CSS files before component files when possible1004. Work through child components before parent components101102---103104## Project Preferences105106### Naming Conventions107- **CSS classes**: `kebab-case` (e.g., `card-header`, `btn-primary`)108- **Component files**: `PascalCase.svelte` (e.g., `UserCard.svelte`)109- **BEM-like modifiers**: Double dash for variants (e.g., `btn--primary`, `card--elevated`)110111### Spacing and Units112- Use `rem` for spacing (0.25rem, 0.5rem, 1rem, 1.5rem, 2rem)113- Use `em` for typography-relative spacing114- Avoid magic numbers - prefer CSS variables115116### Color Management117- Define colors as CSS variables in root/theme118- Never hard-code hex/rgb values in components119- Use semantic naming (`--color-primary`, not `--blue-500`)120- 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.121- 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:122123```css124:root {125 /* Roles on top of the theme tokens */126 --color-primary: var(--accent);127 --color-on-primary: var(--accent-ink);128 --color-danger: var(--danger);129 --color-surface: var(--surface);130 --color-on-surface: var(--ink);131}132```133134### Responsive Design135- Mobile-first approach (min-width media queries)136- Common breakpoints:137 - `sm`: 640px138 - `md`: 768px139 - `lg`: 1024px140 - `xl`: 1280px141142---143144## Permission and Confirmation145146**Always ask permission before:**147- Editing multiple files (confirm per file or batch)148- Making structural changes to component architecture149- Introducing new styling patterns or conventions150- Making changes that affect parent/sibling components151152**Always explain:**153- Why a particular approach is recommended154- What knock-on effects changes might have155- Which order changes will be applied156- Alternative approaches if multiple options exist157158---159160## Success Criteria161162A styling task is complete when:163- Visual issues are resolved across all target breakpoints164- Styling matches project conventions consistently165- No new bugs or regressions introduced166- Code is maintainable and follows project patterns167- User has confirmed the solution meets requirements168- Accessibility checklist passes (contrast, focus, keyboard, screen reader)169- Animations respect `prefers-reduced-motion`