Can I apply a gradient along an SVG path?

Mike Bostock figured out a way, though it’s not easy:
https://bl.ocks.org/mbostock/4163057

Basically, this technique uses getPointAtLength to slice the stroke into many short strokes, specify interpolated color stops for each, and then apply a gradient to each short stroke between those stops.

Good luck if you’re up to the challenge 😉

Edit (July 3rd, 2019):

There is now a library that will help you do exactly what you’re looking for. It’s not required to use D3, but you’re able to if you desire. Here’s a tutorial on Medium.

Leave a Comment