What an SVG file is and why you'd make one

An SVG file (Scalable Vector Graphics) is a text-based image format that stores shapes, lines, and text as mathematical instructions rather than as pixels. When you open an SVG in a browser or design program, it draws those shapes at whatever size you need — on a phone screen or a billboard — without losing sharpness. That's the opposite of a JPG or PNG, which get blurry when you enlarge them.

You create SVG files when you need graphics that stay crisp at any size: logos, icons, charts, maps, or illustrations. They're also much smaller in file size than raster images, and you can edit them by hand if you know what you're doing. Most design tools can export to SVG, but you can also write one directly as code in a text editor.

Key Takeaways

  • SVG files are vector graphics stored as code, so they scale to any size without losing quality.
  • You can create SVGs three ways: using design software like Illustrator or Inkscape, exporting from a tool like Figma, or writing the code directly in a text editor.
  • Inkscape is free, open-source software that works on Windows, Mac, and Linux and exports directly to SVG format.
  • A basic SVG file is plain text that starts with <svg> and contains shape tags like <circle>, <rect>, and <path>.
  • Test your SVG by opening it in a web browser to see how it renders before you use it anywhere else.

Using Inkscape to draw and export an SVG

Inkscape is free software designed specifically for vector graphics and saves directly to SVG. Download it from inkscape.org for Windows, Mac, or Linux. When you open it, you get a blank canvas and a toolbar on the left with drawing tools: the rectangle tool, circle tool, pen tool (for drawing custom shapes), and text tool.

Draw your graphic using these tools. Click the rectangle tool, then click and drag on the canvas to create a rectangle. Use the color palette at the bottom to change the fill color, or right-click a color to change the stroke (outline). Once you're done, go to File > Save As, choose "Scalable Vector Graphics (*.svg)" from the format dropdown, name your file, and click Save. Inkscape writes the SVG code for you automatically.

Exporting from design tools like Figma or Adobe Illustrator

If you already use Figma (a browser-based design tool) or Adobe Illustrator, both can export your work as SVG. In Figma, select the shape or group you want to export, open the Design panel on the right, scroll to the Export section, click the plus icon, choose SVG from the dropdown, and click the download icon. In Illustrator, go to File > Export As, choose SVG from the format dropdown, name your file, and click Export.

Both tools give you options for how to optimize the SVG — whether to include metadata, how to handle text, and whether to minify the code (remove unnecessary characters to make the file smaller). For most uses, the default settings work fine. The exported file is ready to use immediately.

Writing SVG code directly in a text editor

If you're comfortable with code, you can write SVG by hand. Open any text editor (Notepad on Windows, TextEdit on Mac, or a code editor like Visual Studio Code) and start with this basic structure:

<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg"> <circle cx="100" cy="100" r="50" fill="blue" /> </svg>

This creates a 200-by-200 pixel canvas with a blue circle in the center. The cx and cy attributes set the circle's position (100, 100), and r sets the radius to 50 pixels. You can add rectangles with <rect>, lines with <line>, and text with <text>. Save the file with a .svg extension, then open it in any web browser to see how it looks. Edit the code, save, and refresh the browser to see your changes instantly.

Understanding the basic SVG shape tags

Every SVG shape needs a tag and attributes that describe its size, position, and appearance. A <rect> (rectangle) needs x and y coordinates for the top-left corner, plus width and height. A <circle> needs cx and cy for the center point and r for the radius. A <line> connects two points using x1, y1, x2, and y2.

The <path> tag is the most powerful — it lets you draw any shape by listing a series of points and commands. For example, M 10 10 L 90 90 means "move to point 10,10, then draw a line to 90,90." Paths are harder to write by hand, but they're what design tools use under the hood. For simple graphics, stick with rectangles, circles, and lines. For complex shapes, use a design tool and let it write the path code for you.

Adding colors, strokes, and styling to your SVG

Every shape can have a fill (the color inside) and a stroke (the outline color). Use color names like "blue" or "red", or use hex codes like "#FF5733". You can also set stroke-width to control how thick the outline is, and opacity to make a shape transparent (0 is invisible, 1 is fully opaque).

For example: <rect x="10" y="10" width="100" height="50" fill="lightblue" stroke="navy" stroke-width="2" /> creates a light blue rectangle with a navy outline 2 pixels thick. You can also group shapes together using <g> tags and apply styling to the whole group at once, which is useful when you have many related shapes.

Testing and optimizing your SVG file

Before you use your SVG anywhere, open it in a web browser to make sure it renders correctly. Drag the file into a browser window, or right-click the file and choose "Open with" and select your browser. The SVG should display at the size you specified. Resize the browser window — the SVG should stay sharp at any size, which is the whole point.

If you're using the SVG on a website, you can also check it in the browser's developer tools. Right-click the image and choose "Inspect" to see the SVG code and make sure it's loading correctly. If the file is very large or you're using it in many places, you can minify it (remove extra spaces and comments) using an online SVG minifier tool, which shrinks the file size without changing how it looks.

Frequently Asked Questions

Can I convert a JPG or PNG to SVG?

You can trace a raster image and convert it to vector, but it's not a simple one-click process. Inkscape has a "Trace Bitmap" feature (Path > Trace Bitmap) that attempts this, and online tools like Potrace do the same. The result is usually rough and requires cleanup. For best results, redraw the image as a vector from scratch or start with a vector source if you have one.

What's the difference between SVG and PDF?

Both are vector formats, but SVG is designed for the web and works in browsers and web applications. PDF is designed for printing and document sharing. SVG files are smaller and more flexible for web use. If you need to print or share a document, PDF is better. For web graphics and icons, SVG is the right choice.

Can I edit text inside an SVG file?

Yes, if the text was created as an SVG text element (not converted to a path). Open the SVG in a design tool like Inkscape or Figma, select the text, and edit it. If you wrote the SVG by hand, you can edit the text directly in your text editor by changing the content between the <text> tags. If the text was converted to a path, you'll need to delete it and create new text.

How do I make an SVG responsive so it scales on mobile?

Remove the width and height attributes from the <svg> tag and add viewBox="0 0 200 200" instead (replace 200 200 with your actual dimensions). Then set the width and height in CSS or HTML to 100% so it scales with its container. This way, the SVG grows and shrinks to fit the screen without distorting.