No npm needed. One CDN script, one canvas element, and a path to your .riv file. Rive renders GPU-accelerated animations straight into the canvas.
Paste this into your HTML — it loads the Rive WebGL runtime from a CDN.
<script src="https://unpkg.com/@rive-app/webgl@2.9.1"></script>Rive renders into canvas. Set width and height to match your icon size.
<canvas id="rive-icon" width="150" height="150"></canvas>Initialise Rive with your .riv file, artboard name, and state machine. Unicorn Icons use 'State Machine 1'.
const r = new rive.Rive({
src: "your_animation.riv",
canvas: document.getElementById("rive-icon"),
autoplay: true,
artboard: "Main",
stateMachines: ["State Machine 1"],
onLoad: () => console.log("Rive loaded")
});Get the inputs after load and use them to trigger animations on user events. Hover and Clicked are included in every Unicorn Icon.
const canvas = document.getElementById("rive-icon");
const r = new rive.Rive({
src: "your_animation.riv",
canvas,
autoplay: true,
stateMachines: ["State Machine 1"],
onLoad: () => {
const inputs = r.stateMachineInputs("State Machine 1");
const hover = inputs.find((i) => i.name === "Hover");
canvas.addEventListener("mouseenter", () => (hover.value = true));
canvas.addEventListener("mouseleave", () => (hover.value = false));
}
});Why canvas instead of SVG?
Rive uses WebGL for GPU-accelerated rendering — that's what makes state machine transitions so smooth. The trade-off is that canvas content isn't in the DOM, so CSS won't affect the animation visuals.
Where do I get the .riv file?
Download the Rive format from Unicorn Icons. Serve it from a public folder or CDN — it loads over HTTP like any static file.
How do I trigger hover?
In the onLoad callback, get the inputs and find the one named Hover. Set hover.value = true on mouseenter, false on mouseleave. Step 4 shows the full pattern.
Get your animated icons
Browse icons ready for HTML — free to download.