Immediate-mode DOM tools

Usage no npm install needed!

<script type="module">
  import immDom from '';


Immediate-Mode DOM Tools

Lightweight tooling around DOM creation. Designed to be embedded piecewise in self-contained Web Components.

I love virtual DOM libraries like superfine, preact, and inferno. But not all creations need the efficient updating logic. Creations like self-sufficient Web Components, where every byte of superfluous logic is wasted.

The imm-dom library enables concise expression of DOM creation, while never setting innerHTML with uncontrolled content. Elements are created using createElement() or createElementNS(). Strings become Text nodes via createTextNode() or elem.append(). Attributes are set using elem.setAttribute(). DOM injection is protected against, in conjunction with caution and expertise, to provide tools for dynamic content.


See the mini demo and the demo's index.html source.


imm-dom provdes layers of DOM tools:

  • Creating new DOM elements, both HTML and SVG
  • Manipulating (existing) DOM elements
  • Defining Web Components
  • Misc utilities: promises, fences, render animation frames, etc.

Read more in docs/

Immediate Custom Element Web Componet API:

  <imm-demo-cdn data-demo=yes kind=awesome title='my demo title'>
    some body text for the CDN demo

  <script type=module>
    import {imm_html as h, ImmElem} from ''

    ImmElem.elem('imm-demo-cdn', ns =>
        {class: ns.kind},
        h.slot('Body text Slot')) )

Inspired by:

Immediate DOM API:

imm_html.article({class: 'awesome'},
  imm_html.h3('my demo title'),
  'some body text')

// or

tag('article', {class: 'awesome'},
  tag('h3', 'my demo title'),
  'some body text')

Inspired by:

Immediate Template API:

  <article ${ {class: 'awesome'} }>
    <h3>${ 'my demo title' }</h3>
    ${ 'some body text' }

Inspired by:

Immediate requestAnimationFrame API

  • imm_raf() returns a promise for the next requestAnimationFrame tick.
  • ImmRAF is like ImmElem using requestAnimationFrame to decouple attribute updates from rendering.

Size Cost in Bytes

To be embedded in each web component custom element, the individual pieces must be small.

The entire library is ~ 5300 bytes minified; ~ 2250 brotli. However, the library is designed to include only the parts actually used. Perfect for pairing with a tree-shaking tool like rollup.

module brotli minified source
index 2156 B 5270 B 11186 B
imm_elem 554 B 1359 B 2753 B
imm_tmpl 826 B 1693 B 4498 B
imm_dom 511 B 1038 B 2132 B

See auto-generated compressed size report.


BSD 2-clause