SVG Editor
Edit SVG code in your browser and see the result as you type. Replace one color everywhere in the code, then copy the SVG or download it as image.svg. Script tags and quoted event handlers are removed before the preview and the output.
Key features
- Live SVG code preview
- Invalid SVG warning based on the browser XML parser
- Find and replace colors
- Download or copy modified SVG
Guide
SVG (Scalable Vector Graphics) is an XML-based image format that describes shapes, paths, and text using mathematical coordinates rather than pixel grids. Unlike raster formats (PNG, JPEG, WebP), SVG images scale to any size without losing quality. A 24px icon and a billboard-sized logo can use the same SVG file. This makes SVG the standard format for icons, logos, illustrations, charts, and any graphic that needs to render crisply at multiple sizes. This guide covers SVG structure, editing techniques, optimization strategies, and practical use in web development.
An SVG file is a text document. You can open it in any code editor and read it. The root element is <svg> with attributes for width, height, and viewBox. The viewBox defines the coordinate system: viewBox="0 0 100 100" means the drawing area spans from (0,0) to (100,100). Inside the <svg> element, you find shape elements like <rect>, <circle>, <ellipse>, <line>, <polyline>, <polygon>, and <path>. Each element has attributes that define its geometry, fill color, stroke color, stroke width, and other visual properties. Understanding this structure is essential for editing SVGs effectively because every visual change you make in a graphical editor maps to a change in this XML markup.
The <path> element is the most powerful and most complex SVG element. It uses a compact string of commands in its d attribute to describe any arbitrary shape. The commands are: M (move to), L (line to), H (horizontal line), V (vertical line), C (cubic Bezier curve), S (smooth cubic Bezier), Q (quadratic Bezier curve), T (smooth quadratic Bezier), A (elliptical arc), and Z (close path). Uppercase letters use absolute coordinates. Lowercase letters use relative coordinates. A typical path looks like d="M10 10 L90 10 L90 90 L10 90 Z", which draws a square. Complex illustrations contain hundreds of path commands. Editing these by hand is possible but tedious, which is why visual SVG editors exist.
Bezier curves in path data deserve special attention because they define most of the interesting shapes in SVG. A cubic Bezier (C command) takes three coordinate pairs: two control points and an endpoint. The control points pull the curve toward them without the curve actually passing through them, creating smooth arcs. The S command is a shorthand for smooth cubic Bezier that mirrors the previous control point, creating continuous curves. Quadratic Beziers (Q command) use a single control point and are simpler but less flexible. Understanding how control points affect curve shape helps you make targeted edits to path data when you need to adjust a specific curve segment.
The viewBox attribute controls how the SVG content maps to the display area. It takes four values: min-x, min-y, width, and height. The viewBox is independent of the SVG element's width and height attributes. If the SVG element is 200px wide but the viewBox width is 100, each unit in the viewBox maps to 2px on screen. This separation between internal coordinates and display size is what makes SVG truly scalable. Changing the viewBox can crop, pan, or zoom the graphic without modifying any shape data. Adjusting the viewBox min-x and min-y values pans the view. Changing the width and height values zooms in or out.
Fill and stroke are the two primary ways SVG shapes get their color. Fill controls the interior color. Stroke controls the outline color. Both accept color values (hex, rgb, named colors), the keyword none (for no fill or no stroke), or references to gradient and pattern definitions. Stroke has additional properties: stroke-width (line thickness), stroke-linecap (butt, round, or square endings), stroke-linejoin (miter, round, or bevel corners), stroke-dasharray (dashed line patterns), stroke-dashoffset (starting position for the dash pattern), and stroke-opacity. Mastering fill and stroke properties gives you fine control over the visual appearance of every element.
The fill-rule property determines how the interior of complex shapes is calculated. The default value, nonzero, counts the direction of path segments crossing a test ray to determine if a point is inside or outside the shape. The evenodd value counts the number of crossings regardless of direction: odd crossings mean inside, even means outside. This distinction matters for shapes with overlapping or crossing paths. If a shape with a hole in the middle renders as a solid fill, changing fill-rule from nonzero to evenodd (or vice versa) often fixes it.
Gradients in SVG come in two types: linear and radial. A <linearGradient> defines a color transition along a straight line. A <radialGradient> defines a color transition radiating from a center point. Both are defined in a <defs> section and referenced by id from fill or stroke attributes. Each gradient contains <stop> elements that define colors at specific positions along the gradient. For example: <stop offset="0%" stop-color="#ff0000"/> <stop offset="100%" stop-color="#0000ff"/> creates a red-to-blue gradient. Gradients can be reused across multiple elements by referencing the same id. The gradientUnits attribute controls whether gradient coordinates are relative to the bounding box of the element (objectBoundingBox, the default) or to the SVG canvas (userSpaceOnUse).
Patterns in SVG (<pattern> element) define repeating tiles that can fill shapes. A pattern is defined in <defs> with a width and height that determine the tile size, and it contains whatever SVG elements make up one tile. Patterns can contain shapes, paths, images, or even other patterns. They are useful for backgrounds, textures, and repeating decorative elements. The patternUnits and patternContentUnits attributes control how the pattern scales relative to the filled element.
Transforms let you move, rotate, scale, and skew SVG elements without changing their coordinates. The transform attribute accepts translate(x, y), rotate(angle, cx, cy), scale(sx, sy), and skewX/skewY(angle) functions. Transforms are composable: transform="translate(50, 50) rotate(45)" moves an element then rotates it. The order matters because transforms apply right to left (the rightmost transform happens first). Groups (<g> elements) can carry transforms that apply to all their children, letting you move or rotate an entire group of shapes together.
The <g> element groups related shapes. It has no visual presence of its own but acts as a container. Any attributes on a <g> element (fill, stroke, transform, opacity) are inherited by its children unless overridden. Grouping is essential for organizing complex SVGs. A human figure might have groups for the head, torso, left arm, right arm, left leg, and right leg. Each group can be transformed independently, enabling animation or responsive adjustments. Nested groups create a hierarchy that mirrors the logical structure of the illustration.
SVG text uses the <text> element with x and y attributes for positioning. Unlike HTML text, SVG text is positioned in the coordinate system and becomes part of the graphic. You can apply fills, strokes, and transforms to SVG text just like shapes. The <tspan> element creates inline variations within a <text> element (different position, style, or size for part of the text). SVG text remains selectable and searchable, unlike text rasterized in PNG or JPEG images. For logos and icons, convert text to outlines (paths) to eliminate font dependency. For accessible text in charts and diagrams, keep it as <text> elements. The <textPath> element places text along a curved path, useful for circular text, labels on arcs, and decorative typography.
Clipping and masking control visibility of SVG elements. A <clipPath> defines a shape that acts as a window: only the parts of the target element that fall inside the clip shape are visible. Everything outside is hidden with a hard edge. A <mask> uses luminance values to control visibility: white areas of the mask are fully visible, black areas are hidden, and gray areas are partially transparent. Clipping produces hard edges. Masking produces soft, graduated edges. Both are defined in <defs> and applied via clip-path or mask attributes. Clipping is more performant than masking because the browser can skip rendering entirely for clipped regions.
SVG filters (<filter> element) apply visual effects like blur, drop shadow, color manipulation, and compositing. Common filters include feGaussianBlur (blur effect), feDropShadow (shadow behind elements), feColorMatrix (color transformation), feComposite (combining multiple inputs), feDisplacementMap (distortion effects), and feTurbulence (noise generation). Filters are powerful but can be expensive to render, particularly at large sizes. Use them sparingly and test performance on lower-powered devices. For common effects like drop shadows, CSS box-shadow or filter: drop-shadow() applied to the SVG element may perform better than SVG filters.
Optimization is critical for SVG files used on the web. Design tools like Illustrator, Figma, and Sketch export SVGs with unnecessary metadata, editor-specific attributes, empty groups, redundant transforms, and excessive decimal precision in coordinates. An unoptimized SVG icon might be 5KB. After optimization, the same icon might be 800 bytes. SVGO (SVG Optimizer) is the standard tool for this. It removes metadata (titles, descriptions, comments added by editors), removes hidden elements, collapses unnecessary groups, converts shapes to shorter path equivalents, rounds coordinates to fewer decimal places, and minifies the markup. SVGO is configurable through plugins, so you can control exactly which optimizations to apply.
Removing unnecessary precision from path coordinates is one of the biggest size wins. Design tools often export coordinates with 6 or more decimal places: d="M12.847263 45.293847 L67.384726 89.472638". For most web use, 1 or 2 decimal places are sufficient: d="M12.85 45.29 L67.38 89.47". The visual difference is invisible at typical display sizes, but the file size reduction is significant across hundreds of path points. SVGO's cleanupNumericValues plugin handles this automatically. For very small icons (16px to 24px), even 0 decimal places may be acceptable.
Converting basic shapes to paths (or vice versa) affects both file size and readability. A <rect x="10" y="10" width="80" height="80"/> is shorter and more readable than the equivalent path. SVGO can convert simple paths to basic shape elements when the path describes a recognizable shape. In the other direction, some workflows prefer converting all shapes to paths for consistency, particularly when preparing SVGs for animation libraries that work better with path data. Understanding when each approach is better helps you make informed optimization decisions.
Inline SVG versus external SVG files involves tradeoffs. Inline SVG (pasting the SVG markup directly into HTML) eliminates an HTTP request, allows CSS styling of SVG internals, enables JavaScript interaction with SVG elements, and renders immediately without a separate load. External SVG files (via <img> src or CSS background-image) benefit from browser caching, keep HTML smaller, and are simpler to manage. For icons used on every page, inline SVG with a symbol sprite is often the best approach: define all icons once in a hidden <svg> block with <symbol> elements, then reference them throughout the page with <use href="#icon-name"/>. This combines the caching benefit (one sprite file) with the styling benefit (CSS can target the <use> element).
CSS can style inline SVG elements using standard selectors. You can target SVG elements by tag name, class, or id and set properties like fill, stroke, stroke-width, opacity, and transform. This enables hover effects, theme switching (change icon colors between light and dark mode), and responsive adjustments. CSS transitions and animations work on SVG properties, letting you animate color changes, transforms, and opacity without JavaScript. The currentColor keyword is particularly useful: set fill="currentColor" on an SVG element, and it inherits the CSS color property from its parent, making icon color automatic. This is the standard approach for icon systems that need to match text color.
Accessibility for SVG requires explicit effort. Add a <title> element as the first child of the <svg> element for a human-readable name. Add a <desc> element for a longer description if the SVG conveys complex information (like a chart). Set role="img" on the <svg> element and aria-labelledby referencing the title (and optionally desc) element ids. For decorative SVGs that convey no information (backgrounds, ornaments), set aria-hidden="true" and role="presentation" to exclude them from the accessibility tree. For interactive SVGs, add appropriate ARIA roles and keyboard event handlers.
Responsive SVG behavior depends on how width and height are set. An SVG with explicit width and height attributes renders at that fixed size. Remove width and height and set only viewBox, and the SVG scales to fill its container while maintaining aspect ratio. Control the aspect ratio behavior with the preserveAspectRatio attribute. The value xMidYMid meet (the default) scales the SVG to fit inside the container, centered. The value none stretches the SVG to fill the container, ignoring aspect ratio. For responsive icons, remove width and height, keep the viewBox, and control size through CSS on the container or the SVG element itself.
SVG animation can be achieved through CSS animations, the Web Animations API, or JavaScript libraries like GSAP and anime.js. Common SVG animations include path drawing effects (animating stroke-dashoffset to reveal a path progressively), morphing (transitioning one path shape to another), and element-level transforms (rotating gears, bouncing icons, sliding elements). For simple animations, CSS is sufficient. For complex sequenced animations involving multiple elements, GSAP provides a timeline-based approach with fine control over easing, duration, and synchronization. Path morphing requires that the source and target paths have the same number and type of commands, which tools like flubber.js can handle by interpolating between paths with different structures.
SVG sprite systems are the standard approach for icon management on production websites. A sprite file contains multiple icons, each wrapped in a <symbol> element with a unique id. The sprite file is either inlined in the HTML or loaded as an external file. Individual icons are then rendered using <svg><use href="#icon-name"/></svg>. This approach provides a single HTTP request for all icons (if external) or zero additional requests (if inlined), CSS stylability through currentColor and custom properties, and easy icon management through a centralized sprite file. Build tools like svg-sprite and svgo-loader automate sprite generation from individual SVG icon files.
SVG versus icon fonts is a comparison that has been settled in favor of SVG. Icon fonts (Font Awesome, Material Icons as fonts) render icons as text characters in a custom font. They were popular because they offered easy color changes and sizing through font-size and color properties. However, icon fonts have significant drawbacks: they require loading an entire font file even if you use only a few icons, they render as text (which screen readers may announce as gibberish), they are subject to font rendering quirks (anti-aliasing, subpixel rendering), and they cannot be multicolored. SVG icons solve all of these problems. They can be individually included (no loading unused icons), they can carry proper accessibility attributes, they render as graphics (not text), and they support multiple colors, gradients, and animations.
SVG performance considerations include rendering cost, file size, and DOM complexity. Rendering cost increases with the number of path points, the complexity of filters, and the number of elements. An SVG illustration with 10,000 path points will render slower than one with 1,000 points. Simplifying paths (reducing point count while maintaining visual quality) is both an optimization and a file size reduction. DOM complexity matters for inline SVG: each SVG element is a DOM node. An inline SVG with 500 elements adds 500 nodes to the DOM, which can affect layout performance and memory usage. For complex illustrations, consider using <img> tags to keep the SVG out of the main DOM.
SVG security involves preventing injection attacks when SVG content comes from user input. SVGs can contain JavaScript (via <script> elements or event handler attributes like onclick), external resource references (via xlink:href or href attributes), and CSS (via <style> elements). Displaying user-submitted SVG without sanitization is a cross-site scripting (XSS) vulnerability. Sanitize SVGs by removing <script> elements, event handler attributes, external references, and potentially dangerous CSS. Libraries like DOMPurify can sanitize SVG content. If SVG content is displayed via <img> tags, the browser sandboxes it and prevents script execution, making <img> a safer choice for untrusted SVGs.
SVG in data URIs enables embedding SVGs directly in CSS without external files. Encode the SVG markup as a data URI: background-image: url('data:image/svg+xml,...'). This eliminates an HTTP request and is useful for small, frequently used graphics like background patterns, checkmarks, and arrows. URL-encode special characters (# becomes %23, < becomes %3C) or base64-encode the entire SVG. URL encoding produces smaller output than base64 for most SVGs. For inline CSS in HTML, you can also use the unencoded SVG in a data URI if you use single quotes for the URI and double quotes inside the SVG.
The SVG editor tool in the browser lets you edit SVG markup directly and see the visual result in real time. This is particularly useful for making targeted adjustments: changing colors, tweaking path points, adjusting viewBox dimensions, removing unnecessary elements, and testing how changes affect the rendered output. For complex editing tasks like drawing new shapes or manipulating Bezier curves visually, dedicated vector editors like Figma or Inkscape are more appropriate. The browser-based editor suits code-level tweaks and shows how SVG markup maps to visual output. It does not optimize or minify the code. Its color tool replaces every match of one color value in the code, ignoring letter case.
Frequently asked questions
Is my SVG data safe?
Yes, all processing happens in your browser. No data is uploaded to any server.
Can I edit complex SVGs?
Yes, as long as the code is valid XML. Your browser renders the preview, so it shows any SVG element the browser supports. The tool removes script tags, quoted on* event attributes, and the text javascript: from the preview, the copy, and the download.
Is SVG better than PNG for web?
For icons, logos, diagrams, and line art, yes. SVG stays sharp at any resolution and usually weighs far less than a comparable PNG. For photographs and complex gradients, PNG, WebP, or AVIF are better, because raster formats encode photographic detail far more efficiently than vector paths ever can.
How to optimize SVG for web performance?
Run every exported SVG through an optimizer like SVGO. It strips editor metadata, collapses empty groups, rounds coordinate precision, and minifies markup, often cutting file size by 50 to 80 percent. Inline critical icons directly in HTML to skip an extra request, and serve the rest as a cached sprite.
