HTML, SVG and MathML elements in JavaScript.

One function per tag. Props, attributes, children and event listeners go in. A native DOM node comes out.

$ npm install -D fiorejs

No runtime dependencies. TypeScript declarations included.

app.js ESM
import { div, button } from 'fiorejs';

const save = () => console.log('saved');

const card = div
  .props({ className: 'card' })
  .attrs({ 'data-state': 'open' })
  .create(
    button.on({ click: save }).create('Save'),
  );

document.body.appendChild(card);

One job: build the element.

The call creates a node, applies the data you passed and returns it. Every behaviour below links to the line that implements it.

Native nodes, no wrapper

Every tag calls document.createElement and returns that node. There is no wrapper object between your code and the DOM.

lib/core/html.js

Four inputs, one fixed order

Props, attributes, children and listeners are applied in that order, whatever the order of the builder calls.

lib/core/builder.js

Nested props merged in place

A plain object such as style or dataset is merged into the element's existing object. Only own keys are copied, so a polluted prototype never reaches the element.

lib/core/base.js

Children in any shape

Pass nodes, strings, numbers or arrays of them. null, undefined, true and false are skipped.

lib/core/base.js

Listener options

A listener in on can be a function, or an object with handler and options for addEventListener.

lib/core/base.js

Typed to the tag map

Each factory returns the element type from HTMLElementTagNameMap, with the same pattern for SVG and MathML.

lib/core/html.d.ts

One builder, four inputs.

The same builder works for div, circle or mi. Every method is optional, and .create() creates the element. A plain call such as div({ props, attrs, on, children }) takes the same keys.

  1. props

    JavaScript properties, including nested objects such as style.

  2. attrs

    Values passed to setAttribute. null, undefined and false leave an attribute out.

  3. children

    Passed to .create(): nodes, strings, numbers or arrays of them; empty values are skipped.

  4. on

    Listeners are attached after the children, as a handler or as { handler, options }.

panel.js
import { element } from 'fiorejs';

const panel = element('section')
  .props({ className: 'panel' })
  .attrs({ 'aria-label': 'Details' })
  .on({
    click: { handler: onClick, options: { once: true } },
  })
  .create([
    element('h2')('Details'),
    element('p')('Built with functions.'),
  ]);

element(name) returns the tag for a name, with the same methods as the named export, so element('div') works wherever div does.

Every tag has a function.

Named exports for HTML, SVG and MathML. Each entry point ships its own type declarations.

HTML

112 tag functions

import { div, button }
  from 'fiorejs';
lib/html.js

SVG

63 tag functions

import { circle }
  from 'fiorejs/svg';
lib/svg.js

MathML

31 tag functions

import { mi, mfrac }
  from 'fiorejs/math';
lib/math.js

Add it to your project.

Install from npm, import a tag and append the node. The package is ESM and has no runtime dependencies. Coming from version 1.x or html-dom-js? Read Upgrading from 1.x.

  1. Install the package.
  2. Import a tag function or element.
  3. Append the returned node.
$ npm install -D fiorejs
import { div } from 'fiorejs';

document.body.appendChild(
  div('Hello'),
);