Skip to content

@itsy/html

A tiny HTML renderer with just enough features.

A pixel-art spider, the @itsy/html markA pixel-art spider, the @itsy/html mark

A complete example ​

ts
import { html, attrs } from '@itsy/html';

type Link = { href: string; label: string; active?: boolean };

const Link = ({ href, label, active = false }: Link) =>
  html`<a ${attrs({ href, class: ['link', { active }], aria: { current: active ? 'page' : null } })}>${label}</a>`;

const Menu = (title: string, links: Link[]) => html`
  <nav ${attrs({ aria: { label: title }, hidden: !links.length })}>
    <h2>${title}</h2>
    ${links.map(Link)}
  </nav>`;

Menu('Docs & more', [
  { href: '/guide', label: 'Guide', active: true },
  { href: 'javascript:alert(1)', label: '<script>' },
]);
html
<nav aria-label="Docs &amp; more"> <h2>Docs &amp; more</h2> <a href="/guide" class="link active" aria-current="page">Guide</a><a href="about:blank#blocked" class="link">&lt;script&gt;</a> </nav>

Start here, or try it in the browser.

MIT licensed.