---
name: svg-brand-icon-system
description: Clean, optimize, and standardize Recraft or Figma SVG icons and spot illustrations using SVGO, stripping opaque background rects, preserving explicit viewBox grids, binding monochrome strokes to currentColor, and enforcing accessible inline or external embedding rules.
---
# SVG Optimization & Brand Icon System Protocol
Whenever creating, cleaning, or embedding `.svg` brand icons, pictograms, or editorial spot illustrations in a web repository, apply these deterministic engineering rules:
## 1. Mandatory Raw SVG Sanitization (Recraft / Figma Exports)
Before committing any newly generated or exported SVG:
1. **Strip stray canvas backgrounds:** Inspect the root `<svg>` children and remove any full-bleed white/off-white background `<rect>` (`fill="#fff"`, `#ffffff`, `#F7F7F5`) that turns icons into opaque squares on colored or dark surfaces.
2. **Preserve `viewBox` (NEVER strip it):** Confirm every `<svg>` carries an explicit integer `viewBox="0 0 W H"`. Remove fixed pixel `width`/`height` only when inlining responsive UI icons; keep explicit `width` and `height` when rendering via `<img src="...svg">` (`CLS = 0`).
3. **Run SVGO safely with `removeViewBox` disabled:**
```bash
npx svgo -f ./raw-svgs -o ./public/images/icons --multipass --precision=2
```
Ensure SVGO never strips `viewBox`, `role`, or `aria-label`.
## 2. Theme-Safe Color Mapping (`currentColor` & Brand Tokens)
- **Monochrome UI icons (16px–32px):** Replace hardcoded dark fills/strokes (`#000`, `#000000`, `#111`, `#111111`) with `currentColor` so components control color cleanly via semantic CSS classes (`text-ink`, `text-ink-muted`).
- **Duotone brand marks / spot illustrations:** Bind primary ink strokes to `currentColor` and brand accent fills to `var(--accent-signal, #E04420)` so theme flips stay automatic.
- **Never** embed `<style>` blocks with colliding generic class names (`.cls-1`, `.st0`) across multiple inline SVGs on the same page—inline attributes cleanly or prefix IDs uniquely.
## 3. Inline vs. External `<img src>` Decision Rule
- **Inline `<svg>` (`<= 4 KB`, needs `currentColor` or hover transitions):** Add `aria-hidden="true" focusable="false"` for decorative icons beside text labels; add `role="img" aria-label="..."` for standalone icon-only buttons.
- **External `<img src="/images/illustrations/name.svg">` (`> 4 KB` editorial diagrams or multi-color marks):** Always specify exact numeric `width`, `height`, and descriptive `alt` so browsers cache the file cleanly with zero layout shift.
## 4. Verification Gate
After cleaning an icon batch, verify:
- File sizes reduced cleanly (typically `1–4 KB` UI icons, `4–25 KB` spot illustrations).
- Zero `#000000` / `#111111` hardcoded strokes remain on monochrome UI icons.
- Zero unescaped `<script>` tags or external `<image href="data:image/png;base64,...">` raster wrappers disguised inside `.svg` files.