Reference loadSVG()

loadSVG()

This API is experimental

Its behavior may change in a future version of p5.js.

Asynchronously loads an SVG file from path and returns a p5.ShapeCollection.

The recommended approach is async/await in setup(). For SVG content already in memory, use createSVG() instead.

Once loaded, you can inspect and edit the underlying SVG elements using standard DOM methods via the sourceSVG property (e.g. querySelector() and setAttribute()), and re-parse the modified element using createSVG().

Examples

Syntax

loadSVG(path, [successCallback], [failureCallback])

Parameters

path
String: path or URL of the SVG file.
successCallback
Function: function called with the p5.ShapeCollection on success.
failureCallback
Function: function called with the error if loading fails.

Returns

Promise<p5.ShapeCollection>: a Promise resolving to the parsed shape.

Related References