Kotlin is a great fit for this - it has an html dsl library called Kotlinx.html, which works alongside HTMX fantastically. And, you can write a kotlinjs frontend chunk for anything additional you need that HTMX isn't a great fit for. I built a framework for my own use that has typesafe routing & SQL. It's a thing of beauty.
Kotlin is indeed a great backend to pair with HTMX. However I find jte.gg templating superior to kotlinx.html's awkward syntax. You still benefit from working with native Kotljn objects inside the templates. Check it out!