svg
The SVG element embeds scalable vector graphics with size variants, color options, and built-in animations for icons and illustrations.
Description
The <svg> element embeds Scalable Vector Graphics directly in HTML. SVG is resolution-independent, accessible, and styleable with CSS. Vanilla Breeze provides size classes, color variants, and animation utilities for inline SVG.
Unlike raster images, SVG scales to any size without quality loss, making it ideal for icons, logos, and illustrations.
When to Use
- Icons - UI icons that need to scale and change color
- Logos - Brand marks that must be crisp at any size
- Illustrations - Vector artwork and diagrams
- Charts - Accessible data visualizations
- Animations - Animated graphics via CSS or SMIL
When to Use Other Elements
Size Variants
Predefined size classes for consistent icon sizing across your application.
| Class | Size | Use Case |
|---|---|---|
.xs |
0.75rem (12px) | Inline indicators, badges |
.s |
1rem (16px) | Small icons in text |
.m |
1.5rem (24px) | Default icon size, buttons |
.l |
2rem (32px) | Featured icons, nav items |
.xl |
3rem (48px) | Hero icons, empty states |
.xxl |
4rem (64px) | Large illustrations |
Color Variants
Control SVG fill color with utility classes.
currentColor Pattern
Use currentColor in your SVG to inherit the CSS color property. This allows icons to match surrounding text.
Animations
Built-in animation classes for loading indicators and attention-grabbing icons.
Respecting Motion Preferences
Animations should respect prefers-reduced-motion.
Responsive SVG
Full-width SVG for illustrations and diagrams.
Live Examples
Inline with Text
Task completed successfully
Warning: Check your input
Button with Icon
Icon Grid
Accessibility
Decorative Icons
Icons that don't convey information should be hidden from assistive technology.
Informative Icons
Icons that convey meaning need accessible names.
Interactive Icons
Wrap icons in buttons or links with proper labels.
Best Practices
- Use
aria-hidden="true"on decorative icons - Provide
<title>oraria-labelfor meaningful icons - Don't rely on icons alone - pair with visible text when possible
- Ensure sufficient color contrast
- Test with screen readers
Related Elements
CSS Reference
Styles defined in /src/native-elements/svg/styles.css
| Selector | Properties |
|---|---|
svg |
display: inline-block; vertical-align: middle; overflow: visible; |
svg.xs |
inline-size: 0.75rem; block-size: 0.75rem; |
svg.s |
inline-size: 1rem; block-size: 1rem; |
svg.m |
inline-size: 1.5rem; block-size: 1.5rem; |
svg.l |
inline-size: 2rem; block-size: 2rem; |
svg.xl |
inline-size: 3rem; block-size: 3rem; |
svg.xxl |
inline-size: 4rem; block-size: 4rem; |
svg.currentcolor |
fill: currentColor; |
svg.interactive |
fill: var(--color-interactive); |
svg.muted |
fill: var(--color-text-muted); |
svg.spin |
animation: svg-spin 1s linear infinite; |
svg.pulse |
animation: svg-pulse 2s ease-in-out infinite; |