---
name: moai-tool-svg
description: SVG creation, optimization, and transformation specialist. Use when creating vector graphics, optimizing SVG files with SVGO, implementing icon systems, building data visualizations, or adding SVG animations.
version: 1.0.0
category: tool
modularized: true
user-invocable: false
status: active
updated: 2026-01-26
tags: ["svg", "vector", "graphics", "svgo", "optimization", "animation", "icons"]
allowed-tools: Read, Grep, Glob, Bash, WebFetch
related-skills: moai-domain-frontend, moai-docs-generation
context7-libraries: /nicolo-ribaudo/svgo
---
# SVG Creation and Optimization Specialist
Comprehensive SVG development covering vector graphics creation, SVGO optimization, icon systems, data visualizations, and animations. This skill provides patterns for all SVG workflows from basic shapes to complex animated graphics.
---
## Quick Reference (30 seconds)
### Basic SVG Template
```xml
```
### Common Shapes Cheatsheet
Rectangle: ``
Circle: ``
Ellipse: ``
Line: ``
Polyline: ``
Polygon: ``
### Path Commands Quick Reference
Movement Commands:
- M x y: Move to absolute position
- m dx dy: Move relative
- L x y: Line to absolute
- l dx dy: Line relative
- H x: Horizontal line absolute
- h dx: Horizontal line relative
- V y: Vertical line absolute
- v dy: Vertical line relative
- Z: Close path
Curve Commands:
- C x1 y1 x2 y2 x y: Cubic bezier (two control points)
- S x2 y2 x y: Smooth cubic (reflects previous control)
- Q x1 y1 x y: Quadratic bezier (one control point)
- T x y: Smooth quadratic (reflects previous control)
- A rx ry rotation large-arc sweep x y: Arc
### SVGO CLI Commands
Install globally: `npm install -g svgo`
Optimize single file: `svgo input.svg -o output.svg`
Optimize directory: `svgo -f ./src/icons -o ./dist/icons`
Show optimization stats: `svgo input.svg --pretty --indent=2`
Use config file: `svgo input.svg --config svgo.config.mjs`
### Fill and Stroke Quick Reference
Fill properties: fill, fill-opacity, fill-rule (nonzero, evenodd)
Stroke properties: stroke, stroke-width, stroke-opacity, stroke-linecap (butt, round, square), stroke-linejoin (miter, round, bevel), stroke-dasharray, stroke-dashoffset
---
## Implementation Guide (5 minutes)
### SVG Document Structure
The SVG element requires the xmlns attribute for standalone files. The viewBox defines the coordinate system as "minX minY width height". Width and height set the rendered size.
```xml
```
### Creating Reusable Symbols
Symbols define reusable graphics that can be instantiated with use elements. They support their own viewBox for scaling.
```xml
```
### Path Creation Patterns
Simple icon path combining moves, lines, and curves:
```xml
```
Rounded rectangle using arcs:
```xml
```
Heart shape using cubic beziers:
```xml
```
### Gradient Implementation
Linear gradient from left to right:
```xml
```
Radial gradient with focal point:
```xml
```
### SVGO Configuration
Create svgo.config.mjs in project root:
```javascript
export default {
multipass: true,
plugins: [
'preset-default',
'prefixIds',
{
name: 'sortAttrs',
params: {
xmlnsOrder: 'alphabetical'
}
},
{
name: 'removeAttrs',
params: {
attrs: ['data-name', 'class']
}
}
]
};
```
Configuration preserving specific elements:
```javascript
export default {
multipass: true,
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
cleanupIds: {
preserve: ['icon-', 'logo-']
}
}
}
}
]
};
```
### Embedding SVG in React
Inline SVG component:
```tsx
const Icon = ({ size = 24, color = 'currentColor' }) => (
);
```
SVG sprite with use element:
```tsx
const SpriteIcon = ({ name, size = 24 }) => (
);
```
### Text Elements
Basic text positioning:
```xml
Centered Text
```
Text on a path:
```xml
Text following a curved path
```
---
## Advanced Implementation (10+ minutes)
### Complex Filter Effects
Drop shadow with blur:
```xml
```
Glow effect:
```xml
```
### Clipping and Masking
Clip path for cropping:
```xml
```
Gradient mask for fade effect:
```xml
```
### CSS Animation Integration
Keyframe animation for SVG elements:
```css
@keyframes pulse {
0%, 100% { transform: scale(1); opacity: 1; }
50% { transform: scale(1.1); opacity: 0.8; }
}
.animated-circle {
animation: pulse 2s ease-in-out infinite;
transform-origin: center;
}
```
Stroke drawing animation:
```css
.draw-path {
stroke-dasharray: 1000;
stroke-dashoffset: 1000;
animation: draw 2s ease forwards;
}
@keyframes draw {
to { stroke-dashoffset: 0; }
}
```
### Accessibility Best Practices
Always include title and desc for meaningful graphics:
```xml
```
For decorative SVGs, hide from screen readers:
```xml
```
### Performance Optimization
Reduce precision in path data from 6 decimals to 2:
Before: `M10.123456 20.654321 L30.987654 40.123456`
After: `M10.12 20.65 L30.99 40.12`
Convert shapes to paths for smaller file size when appropriate. Use symbols for repeated elements. Apply SVGZ compression for 20-50% size reduction.
For detailed patterns on each topic, see the modules directory.
---
## Module Index
- modules/svg-basics.md: Document structure, coordinate system, shapes, paths, text
- modules/svg-styling.md: Fills, strokes, gradients, patterns, filters, clipping, masking
- modules/svg-optimization.md: SVGO configuration, compression, sprites, performance
- modules/svg-animation.md: CSS animations, SMIL, JavaScript, interaction patterns
---
## Works Well With
- moai-domain-frontend: React/Vue SVG component integration
- moai-docs-generation: SVG diagram generation for documentation
- moai-domain-uiux: Icon systems and design system integration