What is SVG? — Scalable Vector Graphics Explained
Definition
SVG (Scalable Vector Graphics) is an XML-based vector image format for two-dimensional graphics. Unlike raster formats (JPEG, PNG, WebP) that store pixel values, SVG stores mathematical descriptions of shapes — lines, curves, circles, rectangles, and paths. This means SVG images scale to any size without losing quality, making them ideal for logos, icons, illustrations, charts, and UI elements that must look sharp on retina displays and large screens.
How It Works
An SVG file is plain XML containing elements like <rect>, <circle>, <path>, <text>, and <g> (group). The <path> element is the most powerful: its d attribute contains drawing commands (M for moveto, L for lineto, C for cubic bezier, A for arc, Z to close) that describe any shape. SVG can include CSS styling, JavaScript event handlers, filters, gradients, masks, and animations (CSS animations, SMIL, or via the Web Animations API). Browsers render SVG natively; it can also be inline in HTML, loaded via <img>, or used as a CSS background.
Common Use Cases
- ▸Icons and UI components that must look sharp at any resolution or zoom level
- ▸Logos that need to scale from favicon size to billboard size
- ▸Animated UI elements (loaders, transitions) built with CSS or SMIL
- ▸Data visualizations and charts where the output is vector-quality
- ▸Web illustrations that need programmatic manipulation via JavaScript
Example
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<circle cx="50" cy="50" r="40" fill="#4A90E2" />
<text x="50" y="55" text-anchor="middle" fill="white">Hi</text>
</svg>
<!-- Renders as a blue circle with "Hi" text,
scales perfectly to any size -->Related Tools
FAQ
- When should I use SVG versus PNG?
- Use SVG for logos, icons, illustrations, and anything that needs to scale. Use PNG for photographs, screenshots, or images with complex color gradients where vector representation is impractical. SVG is also better for accessibility because text in SVG remains searchable and readable by screen readers.
- Can I style SVG with CSS?
- Yes. When SVG is inline in HTML, you can target SVG elements with CSS selectors and apply colors, sizes, transitions, and animations. This makes SVG icons easy to theme — change a CSS variable and all icons in the set update. External SVG files loaded via <img> cannot be styled with CSS.
- How do I reduce SVG file size?
- SVG files exported from design tools (Figma, Illustrator) often contain unnecessary metadata, editor IDs, and redundant attributes. Tools like SVGO remove this cruft, often reducing file size by 50–80%. Avoid embedding raster images inside SVG as data URIs, as this defeats the purpose of vector format.