interactive, collaborative HTML elements with a single data attribute
playhtml is a fast, small (~300KB), library-agnostic, and expressive library for magically creating collaborative interactive HTML elements that persist their state across sessions. It aims to be infrastructure for creating lived-in, alive internet spaces filled with traces of past visitors and the life of present visitors.
<div id="couch" can-move style="display: inline-block; font-size: 80px">🛋</div>
That's it. The couch is draggable for everyone on the page, and its position persists across sessions.
https://github.com/spencerc99/playhtml/assets/14796580/00e84e15-2c1c-4b4b-8e15-2af22f39db7a
📚 Full documentation →
playhtml is in beta and actively developed. Join the Discord to get help and show what you've built.
30-second install
Vanilla HTML — drop in from a CDN, no build step:
<script type="module">
import { playhtml } from "https://unpkg.com/playhtml";
playhtml.init();
</script>
<div id="couch" can-move style="display: inline-block; font-size: 80px">🛋</div>
React:
npm install playhtml @playhtml/react
import { PlayProvider, CanMoveElement } from "@playhtml/react";
<PlayProvider>
<CanMoveElement>
<div id="couch" style={{ display: "inline-block", fontSize: 80 }}>🛋</div>
</CanMoveElement>
</PlayProvider>;
See getting started for both paths in depth. React users should also read the React API reference.
What's in the box
Built-in capabilities — drop these attributes on any element:
| Attribute | What it does |
|---|
can-move | Drag anywhere; position persists and syncs |
can-toggle | Click to flip an on/off state |
can-spin | Rotate by dragging |
can-grow | Click to scale up, alt-click to scale down |
can-duplicate | Click to clone a target element |
can-mirror | Auto-sync attributes, children, and form state (experimental) |
can-hover | Sync hover state across users |
can-play | Fully custom capability with your own logic |
Each has a live demo and full docs in the capabilities reference.
Beyond capabilities:
- Element data — persistent, synced state scoped to a single element
- Page-level data — shared data channels not tied to DOM elements (counters, votes, etc.)
- Presence & cursors — ephemeral per-user state with custom channels, plus multiplayer cursors
- Events — fire-and-forget broadcasts for transient actions (confetti, pings)
- Shared elements — cross-page and cross-domain state for interconnected sites
- Dynamic elements —
setupPlayElement and selector-id for runtime-added nodes
- SPA navigation — works with Astro ViewTransitions, React Router, Next.js, htmx boost, Turbo
Building with AI
Point any coding agent (Claude, Codex, Cursor, Copilot, ChatGPT, ...) at one guide:
Read https://playhtml.fun/docs/llms.txt first, then help me build a playhtml element that...
Or install it as a skill so your agent picks it up automatically:
npx skills add spencerc99/playhtml --skill building-playhtml-elements
More options in the building with AI guide.
Examples
Help & Community