Skip to content

spencerc99/playhtml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

694 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

playhtml πŸ›πŸŒ npm release Downloads Size

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="font-size: 80px">πŸ›‹</div>

That's it. The couch is draggable for everyone on the page, and its position persists across sessions.

playhtml-demo-2.mov

πŸ“š 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>
<img can-toggle id="lamp" src="lamp.png" />

React:

npm install @playhtml/react @playhtml/common
import { PlayProvider, CanToggleElement } from "@playhtml/react";

<PlayProvider>
  <CanToggleElement>
    <img id="lamp" src="lamp.png" />
  </CanToggleElement>
</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

playhtml works well with coding assistants.

Claude Code users β€” install the plugin for a skill that auto-activates when you ask Claude to build playhtml elements:

claude plugin marketplace add spencerc99/playhtml
claude plugin install playhtml@playhtml

Any other LLM (ChatGPT, Copilot, Cursor, ...) β€” copy the prompt template from the building with AI guide into your conversation.

Examples

Help & Community

Data policy

All data is currently stored by a PartyKit instance under my account and is not encrypted. Anyone with the room name can access the data. Custom persistence options (your own storage backend) are on the roadmap.

Contributing

See CONTRIBUTING.md. Contributions for new built-in capabilities are especially welcome β€” the same can-play API powers all of them.

Support & Maintenance

If you enjoy using this, please consider sponsoring the project. This helps fund the hosting costs for the syncing and persistence services and keeps the library maintained over time.

About

interactive, collaborative html elements with a single data attribute

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

 
 
 

Contributors