Have a look at j2html and webfirmframework based on HTML5 (my favourate one). There are many if you google you will get a lot of opensource libs.
Sample code of webfirmframework :
Div div = new Div(null) {{
new Img(this,
new Src("pic_mountain.jpg"),
new Alt("Mountain View"),
new Style("width:304px;height:228px;"));
new Br(this);
new Audio(this,
new Controls()) {{
new Source(this,
new Src("horse.ogg"),
new Type("audio/ogg"));
new Source(this,
new Src("horse.mp3"),
new Type("audio/mpeg"));
new NoTag(this, " Your browser does not support the audio element. ");
}};
}};
System.out.println(div.toHtmlString());
prints
<div>
<img src="pic_mountain.jpg" alt="Mountain View" style="width:304px;height:228px;"><br/>
<audio controls>
<source src="horse.ogg" type="audio/ogg"></source>
<source src="horse.mp3" type="audio/mpeg"></source>
Your browser does not support the audio element.
</audio>
</div>
You can also use this tool to convert HTML5 to Java/Kotlin code.
j2html sample code :
body(
h1("Heading!").withClass("example"),
img().withSrc("img/hello.png")
).render();
becomes
<body>
<h1 class="example">Heading!</h1>
<img src="img/hello.png">
</body>