HTM (Hyperscript Tagged Markup) is a small JSX-like syntax for virtual DOM using standard JavaScript tagged templates, eliminating the need for a transpiler. Current stable version is 3.1.1, released with TypeScript module support improvements and package exports for Node 12+. It is actively maintained by the Preact team with a regular release cadence. HTM works in all modern browsers and is <600 bytes min+gzip. Key differentiators: no build step required, optional HTML-style quotes, component end-tags, HTML comments, and static subtree caching in v3. It provides off-the-shelf bindings for React and Preact, and can be customized with any hyperscript function. The package ships TypeScript type definitions, supports ESM and CJS, and can be compiled away with babel-plugin-htm for zero runtime cost in production.
npm install htmNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to use htm via CDN with Preact to create and render a component with dynamic content.
Ensure static subtrees (no dynamic values) have no side effects in render functions. If side effects are needed, add a dynamic value (e.g., a prop) to force re-evaluation.
Use ES module import syntax (import) instead of require(). If a CommonJS environment is required, use a bundler like Webpack or Rollup, or downgrade to v2.
Use import { html, render } from 'htm/preact/standalone' instead of the .module.js path.Use ...${props} for spreading props. For boolean attributes, just include the attribute name: <div hidden>.Upgrade to htm >=2.2.0 or use a transpiler like babel-plugin-htm for consistent behavior.
const html = htm.bind(React.createElement);
Use import htm from 'https://unpkg.com/htm?module' and then const html = htm.bind(React.createElement); or import { html } from 'https://unpkg.com/htm/preact?module'.Install preact: npm install preact
Add a key attribute to list items: <li key=${item.id}>${item.name}</li>