Skip to main content

Getting Started

Installation

HtmlFlow requires Java 17 or later and is published on Maven Central. Add the core artifact for Java projects; Kotlin projects add the htmlflow-kotlin artifact, which adds a Kotlin-friendly DSL on top of the core.

pom.xml (Maven)
<dependency>
<groupId>com.github.xmlet</groupId>
<artifactId>htmlflow</artifactId>
<version>5.0.4</version>
</dependency>
build.gradle (Gradle)
implementation 'com.github.xmlet:htmlflow:5.0.4'

Quick Start

The quickest way to produce HTML is HtmlFlow.doc(...), which writes directly to any Appendable: System.out, a StringBuilder, a Writer, or other. Build the document fluently and HtmlFlow emits the markup as you go.

import htmlflow.HtmlFlow;

public class Example {
public static void main(String[] args) {
HtmlFlow
.doc(System.out)
.html()
.head()
.title().text("Getting Started").__()
.__() // head
.body()
.h1().text("Hello, HtmlFlow!").__()
.p().text("Rendered with type-safe HTML.").__()
.__() // body
.__(); // html
}
}

Running either program prints:

<!DOCTYPE html>
<html>
<head>
<title>Getting Started</title>
</head>
<body>
<h1>Hello, HtmlFlow!</h1>
<p>Rendered with type-safe HTML.</p>
</body>
</html>

HtmlFlow.doc(...) renders eagerly and is ideal for one-off documents. When you need to render the same template repeatedly with different data (the common case in a web application), use a reusable HtmlFlow.view(...), which binds a data model and resolves its static HTML only once. That, along with the rest of the API, is covered next in Core Concepts.