A kotlinx.html library provides DSL to build HTML to Writer/Appendable or DOM at JVM and browser (or other JavaScript engine) for better Kotlin programming for Web.
See Getting started page for details how to include the library.
You can build DOM tree with JVM and JS naturally
See example for JavaScript-targeted Kotlin
window.setInterval({
val myDiv = document.create.div("panel") {
p {
+"Here is "
a("https://kotlinlang.org") { +"official Kotlin site" }
}
}
document.getElementById("container")!!.appendChild(myDiv)
document.getElementById("container")!!.append {
div {
+"added it"
}
}
}, 1000L)
You can build HTML directly to Writer (JVM only) or Appendable (both JVM and JS)
System.out.appendHTML().html {
body {
div {
a("https://kotlinlang.org") {
target = ATarget.blank
+"Main site"
}
}
}
}
See wiki pages
See development page for details.