Install
npm install triangles
Mount a background behind any element. The host keeps its content;
the pattern renders behind it, and the same seed, options, and size
always produce the same image.
import TrianglesBackground from 'triangles';
const background = new TrianglesBackground(document.querySelector('#hero'), {
seed: 'launch-2026',
density: 180,
depth: 80
});
Browser script
No build step required — load the IIFE bundle and use the
Triangles global.
<div id="hero"><h1>Content above the background</h1></div>
<script src="https://unpkg.com/triangles/dist/triangles.iife.js"></script>
<script>
new Triangles.TrianglesBackground(
document.querySelector('#hero'),
{ seed: 'launch-2026' }
);
</script>
Methods and export
Instances expose setOptions, setRenderer,
resize, render, getOptions,
getSeed, getSnapshot, toBlob,
toSVGString, and destroy.
background.setRenderer('svg');
const svg = background.toSVGString({ width: 2400, height: 1400 });
const png = await background.toBlob({ width: 2400, height: 1400 });
background.destroy();
toBlob returns a Blob so your app decides
how to download, upload, or persist it.