The short answer
SVG path data is the d attribute of a <path> element in an SVG file, a string of letters and numbers that draws the shape. To get it, open the SVG as text and copy the value inside d="...", use the XML Editor in Inkscape, or run one of the short snippets in this guide to list every path in the file. This site has no SVG to path data tool, because reading path data is a text operation, not an image conversion, so the work happens in a text editor, in Inkscape, or in a snippet on your own computer. Shapes such as rect, circle and ellipse have no d attribute until you turn them into paths, and text must be converted to paths first.
What SVG path data is
An SVG file is XML text, and each shape in it is an element. A <path> element draws any shape, from a straight line to a complex curve, and its d attribute holds the drawing instructions, called path data. The instructions are a string of command letters, each followed by coordinates, such as M12 2 L22 20 L2 20 Z, which draws a triangle.
Only <path> elements have a d attribute. Other shapes store their geometry in their own attributes: a <rect> uses x, y, width and height, a <circle> uses cx, cy and r, and a <polygon> uses points. Text is a <text> element and has no path data at all. That is why the first step of converting SVG to path data is often converting the shapes into paths.
Path data is what other tools read when they need the outline of a shape: animation tools that move an object along a path, canvas drawing code, icon fonts, and cutting machines that follow the outline. The fill color, stroke color and stroke width live outside the d attribute, as separate attributes, so copy those too when the look of the shape matters.
Method 1: copy it from the SVG text
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M12 2 L22 20 L2 20 Z" fill="#c74b31"/>
</svg>For one path, reading the file as text is the fastest method. Every SVG file is readable text, so any text editor shows the path data directly. The worked example below is a red triangle on a 24 by 24 viewBox, and its path data is 20 characters long.
- Open the SVG file in a text editor, or paste it into the SVG editor on this site, which shows the code with a live preview.
- Find the <path> element. A file with several shapes has several <path> elements, so check the fill color or the position to find the one you want.
- Copy the text between the quotes of the d attribute. For the triangle above, that is M12 2 L22 20 L2 20 Z.
- Paste it where it is needed, and keep the original SVG file, so you can go back to it if the pasted copy gets changed.
Method 2: read it in the Inkscape XML Editor
Inkscape shows the path data for any shape you select, and it can also turn other shapes into paths first. Use this method when the shape is a rectangle, a circle, an ellipse or text, because none of those has a d attribute to copy yet.
- Open the SVG file in Inkscape.
- Click the shape to select it. Check the status bar to see what kind of object it is.
- If it is not a path yet, convert it with Path, Object to Path, or press Shift+Ctrl+C. Text becomes a group of letter paths, so ungroup it with Shift+Ctrl+G if you need one letter at a time.
- Open the XML Editor with Edit, XML Editor, or press Ctrl+Shift+X.
- Click the object on the canvas. The XML Editor highlights its element and shows the d attribute with the full path data.
- Click into the d value, copy it, and press Escape without changing anything, so the file stays as it was.
Method 3: list every path with Python
import xml.etree.ElementTree as ET
tree = ET.parse("triangle.svg")
ns = "{http://www.w3.org/2000/svg}path"
for path in tree.getroot().iter(ns):
print(path.get("d"))For a file with many paths, a short script lists them all at once, in file order. Save the triangle from Method 1 as triangle.svg, then run the snippet below in the same folder. It prints each d attribute on its own line.
Method 4: list every path with JavaScript
import { readFileSync } from "node:fs";
const svgText = readFileSync("triangle.svg", "utf8");
const paths = [...svgText.matchAll(/<path[^>]*\sd="([^"]+)"/g)].map(m => m[1]);
console.log(paths.join("\n"));The same job in JavaScript reads the file and pulls out every d attribute with a regular expression. Save this as list-paths.mjs in the same folder as triangle.svg, then run it with node list-paths.mjs. It prints each d attribute on its own line, in file order.
Reading the path commands
Path data is a sequence of commands. Each command is one letter followed by numbers, and the letter decides what the numbers mean. Uppercase letters use absolute coordinates, measured from the top left corner of the viewBox. Lowercase letters use relative coordinates, measured from the current point, so l 10 0 draws the same line as L 22 20 when the current point is 12 20. The table decodes the triangle from Method 1.
| Command | What it does | In the triangle |
|---|---|---|
| M | Move to a point, start a new shape | M12 2, the top corner |
| L | Draw a straight line to a point | L22 20, the bottom right corner |
| L | Draw a straight line to a point | L2 20, the bottom left corner |
| Z | Close the path, line back to the start | Z, back to the top corner |
What to do with path data
- Paste the d string into a new <path> element to reuse the shape in another SVG file, keeping the same viewBox so the coordinates still fit.
- Use it in CSS motion path, as offset-path: path("M12 2 L22 20 L2 20 Z"), to move an element along the outline in a web animation.
- Use it in canvas code with new Path2D("M12 2 L22 20 L2 20 Z"), which draws the same shape on an HTML canvas.
- Feed it to an icon font builder or an animation tool that takes raw path data as its input.
- Send it to a cutting machine or laser cutter that reads SVG paths, after checking that the shape is closed with Z when it must cut as a region.
- Copy the fill and stroke attributes with it. The d string holds the outline only, so a pasted path with no fill renders as a black fill by default.
Checks before you use path data
- Check for a transform attribute on the path or on a parent group. A transform moves, rotates or scales the rendered shape without changing the d string, so apply the transform first or the pasted path lands in the wrong place.
- Check the viewBox. Path coordinates mean nothing without it, so keep the viewBox of the source file or scale the numbers to the new file.
- Check grouped paths. A <g> element can hold many paths, and each one has its own d string, so copy every path the shape needs.
- Convert text to paths before copying. Live text has no d attribute, and a missing font changes the lettering on another computer.
- Expect very long d strings from traced artwork. A traced logo can hold thousands of points, so simplify it in Inkscape with Path, Simplify before you copy the data anywhere that has a size limit.
- Test the new file in a browser. Open the SVG with the pasted path data and confirm the shape looks the same as the original.
Sources
Written by Shahab Uddin. Published ; updated . Corrections are welcome through the contact page.