fluent-html
Type-safe, chainable HTML builder for TypeScript with zero dependencies
Type-safe, chainable HTML builder for TypeScript with zero dependencies
fluent-html is a chainable, type-safe HTML builder for TypeScript. It replaces template strings and JSX with pure function calls that return chainable tag objects — every element, attribute, HTMX option, and Tailwind value is autocompleted and validated at compile time. Zero dependencies, ~15KB minified, built for server-side rendering. It powers every SSR application at JT Digital.
Building server-rendered HTML in TypeScript forces a bad trade-off. Template literals give zero type safety and no XSS protection. Template engines like EJS or Pug introduce a separate syntax with no IDE support. JSX requires a build step and a virtual DOM runtime that adds complexity to what should be a simple string-rendering task. None of these options give developers the autocomplete, refactoring, and compile-time validation they expect from TypeScript.
HTMX makes this worse — hx-target="#userList" silently fails when the element has id="user-list". Route paths are duplicated between views and controllers. Tailwind classes are unvalidated strings. The entire UI layer becomes a minefield of runtime bugs that the type system could have caught.
fluent-html models HTML as plain TypeScript function calls. Div(H1("Title"), P("Body")) returns a chainable object with typed methods for every attribute, style, and HTMX option. The compiler catches typos, missing parameters, and invalid values before the code ever runs.
Type-safe HTMX integration means routes defined with defineRoutes() are shared between views and controllers — path parameters are extracted at the type level, and targets created with defineIds() are compile-time validated across files. The fluent Tailwind API replaces class strings with chainable methods like .background("blue-500").padding("4").rounded("lg"), each with full autocomplete.
All text content and attributes are automatically XSS-escaped. The library ships with zero dependencies and renders to strings on the server with no virtual DOM overhead.
defineRoutes() for compile-time validated endpoints, defineIds() for validated targets, morph swaps, partial multi-swap, status-code routing.background(), .padding(), .flex(), .rounded() and 50+ chainable methods replace class strings, with .on() for pseudo-classes and .at() for breakpointsRaw() opt-in for trusted contentIfThen with nullable narrowing, Match with discriminated union support, ForEach with three overloadshx-on:* attributes for toggle, clipboard, remove, disable, and more — no client-side runtimefoldView with pre-built and custom algebrasInternal project management tool built for how we actually work
Financial management and business operations platform for digital agencies
AI design system that turns natural language into production-ready HTML