Keep an SVG gradient continuous across shapes

Fix a color jump where two panels share one linear gradient.

Asset preparation2 min read

Two adjacent rectangles can use the same SVG gradient and still meet at a hard color jump. By default, objectBoundingBox fits the full transition to each rectangle, so it starts again at the second panel. Use userSpaceOnUse when the color should progress across both.

Give the panels one gradient span

Open the editable SVG. Both rows have an 80-unit panel followed by a 160-unit panel. The join is at x=80.

Two rows of violet-to-orange gradient. The top row jumps from orange back to violet at one third. The bottom row continues through the join.

In the top row, x1="0" x2="1" runs from the left to right edge of each shape in its own bounding box. In the bottom row, x1="0" x2="240" spans both rectangles in their shared coordinate system.

svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 48">
  <defs>
    <linearGradient id="banner" gradientUnits="userSpaceOnUse" x1="0" x2="240">
      <stop offset="0" stop-color="#6746ff"/>
      <stop offset="1" stop-color="#ffab34"/>
    </linearGradient>
  </defs>
  <rect width="80" height="48" fill="url(#banner)"/>
  <rect x="80" width="160" height="48" fill="url(#banner)"/>
</svg>

At the seam, the shared gradient is one third of the way from violet to orange on both sides. To reproduce the jump, change the gradient to gradientUnits="objectBoundingBox" x1="0" x2="1". The left panel then ends in orange and the right one starts in violet. SVG 2 gradient coordinates.

Check the coordinate system after export

The example positions the right panel with its x attribute. If your export places the right panel inside a translated or scaled group, the gradient uses that panel's current coordinate system. Move both shapes into a shared coordinate system or compensate for the transform, then inspect the seam in the exported SVG. Keep the default bounding-box mode when each shape should show the full transition on its own.

Image tools
All guides
Keep an SVG gradient continuous across shapes | Formatry Media — Formatry