j2html is a fast and fluent Java Html5 builder from the authors of the Javalin web framework. It allows the developer to code HTML documents using Java code with type safety and in a preferred language and development environment.

To see a simple example, add the j2html dependency.


Use the TagCreator to get started. j2html's syntax is fluent and closely matched to HTML:

import static j2html.TagCreator.*;

public class Main {
    public static void main(String[] args) {
            h1("Hello, World!"),

The Java code above becomes the HTML below:

    <h1>Hello, World!</h1>
    <img src="/img/hello.png">

As a Java developer I like the idea of staying within a single language for both generation and rendering of web content.

I'm going to explore how far I can push this concept, starting with the blog and re-developing it using the j2html library instead of jekyll.

It will be interesting to see if it feels more or less productive to code with that the typical code in a html template or javascript framework. My recent experience with the hilla framework left me feeling that the learning curve was too steep and required too broad a knowledge for me to start using effectively.