Skip to content

FartLabs/ht

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSR version JSR score GitHub Actions

Type-safe HTML string rendering library for JavaScript and TypeScript.

API documentation

Generated API documentation is available at https://jsr.io/@fartlabs/ht.

Getting started

1. Install Deno.

2. Start a new Deno project.

deno init

3. Add html as a project dependency.

deno add jsr:@fartlabs/ht

4. 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.ts

Resulting index.html:

<a href="https://jsr.io/@fartlabs/ht">@fartlabs/ht</a>

Examples

Multiple attributes

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>

Nested elements

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>

Void elements

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">

Full document

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);

Contribute

We appreciate your help!

Style

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.

Development

  • The library has no runtime dependencies.
  • The element functions are generated from @mdn/browser-compat-data and MDN references.
  • If you add or adjust generation logic, run deno task generate and commit the resulting edits.

License

This project is licensed under the terms of the MIT License. See LICENSE for details.


Developed with ❤️ @FartLabs

About

An HTML rendering library.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published