Building HTML Canvases
PostHogOfficialPublished by PostHog
- Skill
- Guidelines
- Software development
- MIT
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides best practices for creating PostHog canvases that function as documents, articles, or generative graphics rather than standard applications. It outlines how to use a thin React wrapper to host semantic HTML, CSS, and imperative browser APIs like WebGL or 2D canvas. The guide covers structural requirements, styling techniques that respect the platform's theme, and essential patterns for resource cleanup and data integration.
What it does
- Defines the structure for using a thin React wrapper to host custom HTML and browser APIs.
- Provides patterns for imperative rendering using 2D canvas and WebGL contexts.
- Explains how to implement theme-aware styling using CSS variables and Tailwind utilities.
- Details resource cleanup patterns to prevent memory leaks during remounts.
- Outlines rules for integrating PostHog data and maintaining verifiability in documents.
- Specifies constraints for network requests and external link handling.
When to use it
- When building a canvas that acts as a document, article, or generative art piece.
- When React components do not provide useful structure for the intended experience.
- When implementing custom drawing surfaces or WebGL scenes within a canvas.
- When you need to style content that must adapt to PostHog's light and dark themes.
Advantages
- Enables the creation of highly customized visual and document-based experiences.
- Ensures consistent theme integration across different PostHog environments.
- Prevents common issues like layout clipping or platform token conflicts.
- Promotes stable canvas behavior through proper lifecycle and cleanup management.
Usage examples
- “How do I structure a canvas that uses a WebGL animation?”
- The guide instructs you to use a thin React wrapper, render a canvas element, and drive the animation imperatively via a useEffect hook with proper cleanup.
- “How should I handle colors for a custom canvas to support dark mode?”
- You should define CSS variables under :root and html.dark, or use theme token utilities, while avoiding hardcoded colors and platform token name collisions.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/posthog/building-html-canvases/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip building-html-canvases.zip -d .agents/skills
Documentation by PostHog
Building HTML canvases
Some canvases are documents or graphics programs, not applications: a written report, a diagram, a generative-art piece, a WebGL scene. For these, semantic HTML, CSS, and direct browser APIs are the right tools — don't force Quill components or React state onto a static page.
The wrapper the current runtime requires
Every canvas keeps src/canvas.tsx as its mounted React entry component (default export, no
props). Keep the React layer as a thin shell and write the
experience in HTML/CSS/browser APIs inside it:
A document is JSX that is effectively semantic HTML —
<article>, headings, lists, tables, figures — with a<style>block for typography and layout. Write real, specific copy.A drawing/WebGL program renders a
<canvas>element and drives it imperatively from auseEffectvia a ref: get the 2D/WebGL context, run the setup and render loop there.Clean up in the effect's return: cancel
requestAnimationFrameloops, remove listeners, and release contexts, so theme switches and remounts don't leak or double-run.Mixing tiers is fine: a mostly static page can mount one interactive island, and a data board can hand a chart's
<canvas>to imperative code while React owns the chrome.
The import allowlist still applies (react, react-dom, @posthog/quill, recharts, lucide-react,
dayjs) — browser globals (document, CanvasRenderingContext2D, WebGLRenderingContext,
requestAnimationFrame, IntersectionObserver, Web Audio, etc.) need no import. Three.js and
other npm graphics libraries are not yet loadable; write against raw WebGL or 2D canvas until the
build pipeline's dependency admission ships.
Styling and theme without Quill
Size the outermost JSX/HTML element to the iframe viewport with
min-h-screenormin-height: 100vh, so it fills the viewport and grows past it as content demands. Do not useh-screenorheight: 100vhthere: a fixed viewport height caps a flex column, so tall children shrink and clip instead of scrolling. Do not useh-fullorheight: 100%on that root either: a published canvas's artifact shell gives itshtml,body, and#rootelements no explicit height, so percentage height collapses to the content height. Amin-heightroot is not a definite height, so a descendant's percentage height still collapses; give an intermediate wrapper an explicit height when a child must fill a box.Use Tailwind utilities and/or a
<style>block (keyframes and complex selectors are fine).The host toggles a
.darkclass on the document root when the user's PostHog theme changes. Define your colors as CSS variables under:root { … }with overrides underhtml.dark { … }, or use theme token utilities (bg-background,text-foreground,border-border) — never a light-only hardcoded color.Give your own CSS variables a prefix (
--doc-bg,--doc-muted). Never reuse a platform token name: the bundled Quill stylesheet sets--background,--border,--card,--chrome,--input,--muted,--primary, and--fill-*on every element, so a:rootorhtml.darkvalue with one of those names never reaches any element. A page that colors its text with its own--mutedthen renders unreadable (pale text on a pale page). Validation rejects such a declaration withplatform_token_redeclared.For canvas/WebGL drawing colors, read the resolved token at runtime (
getComputedStyle(document.documentElement).getPropertyValue("--primary")) or your own CSS variables, and re-read on theme change if the scene is long-lived.
Rules that still apply
PostHog data comes only through the
phbridge (seequerying-canvas-data), includingph.capturefor interaction analytics. Other requests and external styles, images, fonts, media, or frames require their exact public HTTPS origins incapabilities.network.originsand work only after publishing. Remote scripts and dynamic imports remain blocked.A document that states PostHog numbers must make each one verifiable: an insight-backed number links its saved insight through
ph.openExternal(URL from thegenerate-app-urlMCP tool, from a click); an ad-hocph.querynumber discloses the exact query that ran in a<details>element beside the claim — see "Verifiability" inquerying-canvas-data.External links go through
ph.openExternal(url)(posthog.com origins only), from a user interaction.Validate and publish through the canvas tools as described in
validating-and-publishing-canvases.
Files
- ATTRIBUTION.mdAdded by AutoGineer863 B
- LICENSELicence file added by AutoGineer1.0 KiB
- SKILL.md5.0 KiB
LICENSE
MIT License Copyright (c) 2025 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- PostHog
- Publisher
- PostHog (Official)
- Source
- PostHog/skills · skills/omnibus/building-html-canvases · commit a5d30e7
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by PostHog.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download building-html-canvases.zip