Type-safe HTML string rendering library for JavaScript and TypeScript.
Generated API documentation is available at https://jsr.io/@fartlabs/ht.
1. Install Deno.
2. Start a new Deno project.
deno init3. Add html as a project dependency.
deno add jsr:@fartlabs/ht4. Add a file ending in .[j|t]s to your project. For example, main.ts.
import { a } from "@fartlabs/ht";
const html = a({ href: "https://jsr.io/@fartlabs/ht" }, "@fartlabs/ht");
Deno.writeTextFileSync("index.html", html);5. Compile your html by running the .[j|t]s file.
deno run --allow-write main.tsResulting index.html:
<a href="https://jsr.io/@fartlabs/ht">@fartlabs/ht</a>import { a } from "@fartlabs/ht";
const link = a(
{
href: "https://example.com",
rel: "noopener noreferrer",
target: "_blank",
class: "btn",
},
"Visit example.com",
);
// <a href="https://example.com" rel="noopener noreferrer" target="_blank" class="btn">Visit example.com</a>import { a, div, h1, p } from "@fartlabs/ht";
const content = div(
{ id: "app" },
h1({}, "Hello"),
p(
{},
"Made with ",
a({ href: "https://jsr.io/@fartlabs/ht" }, "@fartlabs/ht"),
),
);
// <div id="app"><h1>Hello</h1><p>Made with <a href="https://jsr.io/@fartlabs/ht">@fartlabs/ht</a></p></div>import { br, img, input } from "@fartlabs/ht";
const markup = [
img({ src: "/logo.png", alt: "Logo" }),
br(),
input({ type: "text", name: "q", placeholder: "Search" }),
].join("");
// <img src="/logo.png" alt="Logo"><br><input type="text" name="q" placeholder="Search">import {
a,
body,
footer,
head,
header,
html,
main,
meta,
p,
title,
} from "@fartlabs/ht";
const page = html(
{ lang: "en" },
head(
{},
meta({ charset: "utf-8" }),
meta({ name: "viewport", content: "width=device-width, initial-scale=1" }),
title({}, "My Page"),
),
body(
{},
header({}, p({}, "Welcome!")),
main({}, p({}, "See ", a({ href: "https://jsr.io/@fartlabs/ht" }, "docs"))),
footer({}, p({}, "© 2025")),
),
);
// Write to a file
// Deno.writeTextFileSync("index.html", page);We appreciate your help!
Run deno fmt to format the code.
Run deno lint to lint the code.
Run deno task generate to regenerate the typed HTML element functions from MDN
data. This updates element/attribute typings and (re)creates files in
lib/html-elements/.
Other helpful tasks:
deno task outdated: Review available dependency updates.
- The library has no runtime dependencies.
- The element functions are generated from
@mdn/browser-compat-dataandMDNreferences. - If you add or adjust generation logic, run
deno task generateand commit the resulting edits.
This project is licensed under the terms of the MIT License. See LICENSE for
details.
Developed with ❤️ @FartLabs