Getting started
Install Lava and fill a box with a lava lamp: in React, or in any element, alone or behind content.
npm install @cesarvenzac/lavaPlain TypeScript, published as ES modules with their types, and no dependencies. React is an optional peer, for the React entry alone. It draws with WebGL 2 and a float target to render into, which every current browser has; where there's none, the box shows the liquid lit from below.
A first lamp
lava lays a lamp in an element. The element is the lamp: give it a size, and the wax fills it.
import { lava } from "@cesarvenzac/lava";
const lamp = lava(document.querySelector(".lamp")!, {
palette: "magenta",
});It comes in five palettes, or colours of your own: Colours and light. How it moves, and how it behaves on a page: Motion and the page.
In React
Lava is a <div> with a lamp in it. Its other props go on the <div>:
import { Lava } from "@cesarvenzac/lava/react";
<Lava palette="magenta" className="h-[30rem]" />;A server draws the liquid lit from below, as a CSS background, and the wax fades in over it once the browser has drawn it: nothing moves as the page hydrates. It's a client component, React 18 or later.
Behind content
A lamp on its own is a picture, named by label for assistive tech. With content inside, it's that content's background, drawn under it, and says nothing itself:
<Lava palette="ember" className="grid h-[36rem] place-items-center">
<h1 className="text-white">Slow down</h1>
</Lava>lava() does the same with an element that has children: its canvas lies under them, in a stacking context of the element's own.