If you’ve ever had to change an SVG icon, chart line or animation path from JavaScript, you know the routine: read the d attribute, split a string like "M0,0 h64 v64 h-64 z" with a regex, change the numbers, and glue it back together. The SVG Path Data API replaces that with structured data. A path becomes an array of { type, values } objects that you can read, edit and write back.

Firefox has supported it since version 137. Now Chrome 160, whose beta started on 2 December 2026, lists the API in its release notes ahead of a stable release scheduled for 5 January 2027. This tutorial shows the three methods, gives practical examples, and covers feature detection so you can use it safely before every browser supports it.

The three methods

According to Chrome’s feature entry and MDN, SVGPathElement gains:

  • getPathData(options?) returns the path as an array of segments
  • setPathData(pathData) replaces the path with an array of segments
  • getPathSegmentAtLength(distance) returns the segment found at a given distance along the path

Each segment is an object with a type (the path command letter, such as "M", "h" or "C") and values (the command’s numbers).

Reading path data

Take a simple square:

<svg width="64" height="64" viewBox="0 0 64 64">
  <path id="box" d="M0,0 h64 v64 h-64 z" />
</svg>
const path = document.querySelector("#box");
console.log(path.getPathData());
// [
//   { type: "M", values: [0, 0] },
//   { type: "h", values: [64] },
//   { type: "v", values: [64] },
//   { type: "h", values: [-64] },
//   { type: "Z", values: [] }
// ]

The raw form keeps your commands exactly as written, including relative ones like h and v. This output comes from the MDN getPathData() reference.

Normalising to four commands

Pass { normalize: true } to convert everything into absolute M, L, C and Z commands. That’s much easier to work with, because you only handle four segment types:

console.log(path.getPathData({ normalize: true }));
// [
//   { type: "M", values: [0, 0] },
//   { type: "L", values: [64, 0] },
//   { type: "L", values: [64, 64] },
//   { type: "L", values: [0, 64] },
//   { type: "Z", values: [] }
// ]

Chrome’s entry says normalisation simplifies paths to “absolute move, line, cubic Bézier, and close commands”. Arcs and quadratic curves are converted to cubic curves.

Writing path data back

setPathData() takes the same structure. Here’s a small helper that scales any path around the origin:

function scalePath(pathEl, factor) {
  const segments = pathEl.getPathData({ normalize: true });
  for (const seg of segments) {
    seg.values = seg.values.map((v) => v * factor);
  }
  pathEl.setPathData(segments);
}

scalePath(document.querySelector("#box"), 0.5);
// d becomes something like "M 0 0 L 32 0 L 32 32 L 0 32 Z"

Note that the browser rewrites the d attribute in its own format. Commas become spaces and normalised commands are written out in full. Don’t compare d strings in tests. Compare the result of getPathData() instead.

Finding the segment at a distance

getPathSegmentAtLength() tells you which segment sits at a point along the path. On the 64×64 square, the first edge is 64 units long, so 65 units in lands on the second edge:

console.log(path.getPathSegmentAtLength(65));
// { type: "v", values: [64] }

That works well with the existing getTotalLength() and getPointAtLength() methods. You can build a progress tracker that shows which step of a drawn route the user has reached:

const route = document.querySelector("#route");
const total = route.getTotalLength();

function onProgress(fraction) {
  const distance = total * fraction;
  const point = route.getPointAtLength(distance);
  const seg = route.getPathSegmentAtLength(distance);
  marker.setAttribute("transform", `translate(${point.x} ${point.y})`);
  status.textContent = `On a ${seg.type === "C" ? "curve" : "straight"} section`;
}

A practical example: editable chart points

Say you draw a sparkline as a single path and want to drag one data point. With the Path Data API, you change one segment instead of re-parsing the whole string:

const line = document.querySelector("#sparkline");

function movePoint(index, newY) {
  const segs = line.getPathData({ normalize: true });
  const seg = segs[index];          // M or L segment for that point
  if (seg && (seg.type === "M" || seg.type === "L")) {
    seg.values[1] = newY;           // values are [x, y]
    line.setPathData(segs);
  }
}

Things to know before you rely on it

  • It works on the d attribute only. Chrome’s entry says all three methods operate on the base value of d, “not CSS-computed or animated values”. If you set the path with the CSS d property or animate it, getPathData() won’t reflect that.
  • Browser support is still partial. MDN’s compatibility data lists Firefox 137+. Chrome adds it in 160 (beta now, stable scheduled for January). Safari isn’t listed yet. MDN marks the methods as experimental.
  • Use feature detection and keep your old string-based code as a fallback:
const supportsPathData =
  typeof SVGPathElement !== "undefined" &&
  "getPathData" in SVGPathElement.prototype;

function getSegments(pathEl) {
  if (supportsPathData) return pathEl.getPathData({ normalize: true });
  return legacyParse(pathEl.getAttribute("d")); // your existing parser or a polyfill
}

Also in Chrome 160 for HTML authors

The same release notes include a small HTML change worth checking: anchor name matching becomes case-sensitive in quirks mode. A link to #Foo will no longer jump to <a name="foo"> on pages without a doctype. That matches standards mode, Safari, Firefox and the HTML spec. If you look after old pages that rely on mismatched anchor case, fix the anchors or add <!DOCTYPE html>.

Takeaway

The SVG Path Data API turns path strings into data you can edit, with normalisation that reduces every path to four commands. Firefox already has it, and Chrome 160 brings it to Chromium in January. Use it behind a feature check today, delete your regex path parser once your users have upgraded, and see the MDN reference and the SVG paths spec for the full details.