Change SVG Stroke Color with JavaScript

Recolor stroke in the markup and copy a JavaScript setAttribute snippet

CSS? Stroke + CSSReact? Stroke + React

FAQ

Quick answers

How do I change SVG stroke color with JavaScript?
Paste the SVG, click Recolor stroke + copy JS, then adapt the copied snippet to query your inline SVG nodes.
Does this mutate the file in the editor?
Yes. Stroke colors update in Source and preview; the clipboard also gets a small JS example.
Inline SVG in the DOM?
Use Change Inline SVG Stroke Color for markup aimed at HTML embeds, then wire the JS snippet to those nodes.
Want CSS instead of JS?
Open Change SVG Stroke Color with CSS for a currentColor + stylesheet approach.
Change stroke color → Stroke + CSS → Inline stroke → Stroke + React →
Open full editor →

Source

Type or paste SVG markup. The preview on the right updates as you type.

Ready

Live preview

PNG export · 2× for retina