Skip to main content

Write HTML with Compile-Time Safety

HtmlFlow is a Java DSL for building typesafe HTML templates in a fluent style. Get full IDE support, type checking, and excellent performance.

HtmlFlow Logo
Maven Central
GitHub Stars

Type-Safe HTML Generation in Java and Kotlin

Write HTML in a typesafe, fluent style. Your IDE will guide you through valid HTML 5.2 structure.

HtmlFlow DSL
1HtmlFlow
2  .doc(System.out)
3    .html {
4      head {
5        title { text("Hello World!") }
6      }
7      body {
8        div {
9          attrClass("container")
10          h1 { text("Hello World!") }
11          img { attrSrc("http://bit.ly/2MoHwrU") }
12          p { text("Typesafe is awesome! :-)") }
13        }
14      }
15    }
Output
1<html>
2  <head>
3    <title>HtmlFlow</title>
4  </head>
5  <body>
6    <div class="container">
7      <h1>My first page with HtmlFlow</h1>
8      <img src="http://bit.ly/2MoHwrU">
9      <p>Typesafe is awesome! :-)</p>
10    </div>
11  </body>
12</html>

Use Flowifier.fromHtml(String html) to convert existing HTML to HtmlFlow DSL

Reactive Hypermedia

Type-Safe Datastar Integration

Compose client-side reactivity and signals natively in Kotlin. HtmlFlow converts type-safe expressions like !fetching and get(...) into valid Datastar hypermedia attributes.

HtmlFlow Datastar DSL (Kotlin)
Type-Safe
1button {
2  val fetching = dataIndicator("_fetching")
3  dataAttr("disabled") { +fetching }
4  dataOn(Click) {
5    !fetching and get(::clickToLoadMore)
6  }
7  text("Load More")
8}
Generated Datastar HTML
Compiled Markup
1<button
2  data-indicator:_fetching
3  data-attr:disabled="$_fetching"
4  data-on:click="!$_fetching && @get('/examples/click_to_load/more')"
5>
6  Load More
7</button>

Reactive Signals

Define indicators like _fetching as strongly typed Kotlin variables instead of raw magic strings.

Infix Expression Operator

Combine conditions natively with and or or operators directly inside event builders.

Backend Method Binding

Pass backend function references like ::clickToLoadMore to safely map endpoint URIs at compile time.

Why Choose HtmlFlow?

Typesafe & Compliant

Write valid HTML 5.2 with compile-time safety. Catch errors before runtime with full IDE support and type checking.

High Performance

Optimized for speed with excellent throughput and low overhead. Check the benchmarks to see performance results.

Pure Java/Kotlin

Templates are plain Java functions. No new templating language to learn. Use the full Java toolchain for templating.

Asynchronous Support

Bind to async data models seamlessly. Works with Reactive Streams, CompletableFuture, Kotlin coroutines, and any asynchronous API for progressive rendering.