Repeat or mirror an SVG gradient

Use spreadMethod to control what happens after the gradient reaches its last color.

Asset preparation2 min read

A banner fill turns solid halfway across, or a sharp stripe appears where the gradient starts over. Check whether the gradient's start and end points sit inside the shape. The SVG attribute spreadMethod controls the fill beyond those points.

Compare the three fills

Open the editable SVG. All three bars are 480 units wide and share the same 120-unit horizontal gradient, from orange to violet. Only spreadMethod changes.

  • pad (default). Violet stays solid from the 120-unit mark to the edge. Use it for a single transition.
  • repeat. Violet snaps back to orange every 120 units. Use it when the hard edges are part of the pattern.
  • reflect. Violet blends back toward orange after the 120-unit mark. At 240 units the direction changes again. Use it for a continuous fill with alternating transitions.

Apply it to your export

Set the attribute on the linearGradient definition, for example spreadMethod="reflect". The shape still uses the same fill="url(#gradient)". If the fill shows just one transition, check that the gradient ends inside the shape. In this example gradientUnits="userSpaceOnUse" makes the coordinates literal SVG units and x1="0" and x2="120" set the length of each leg. Halve x2 in the sample and the first reversal moves to 60 units. SVG 2 reference for spreadMethod.

Use reflect if the reversed rhythm suits the artwork. If direction matters each time, keep repeat and make the first and last stops the same color to avoid a jump. Check the exported file at its intended display size and look at the first seam.

Image tools
All guides