Skip to content
javahacks.dev
Vaadin

Vaadin vs Thymeleaf and htmx for Java Web Applications

Compare Vaadin with Thymeleaf plus htmx for Java teams: server side state or HTML over the wire, component depth, testing, SEO and scaling behaviour.

5 min read
Summarize in AI
Flat illustration of a browser page built from server-side components, with the Vaadin, Thymeleaf, OpenJDK and HTML5 logos.

Vaadin and the pairing of Thymeleaf with htmx both keep the logic in Java and avoid a separate single page application. They sit at opposite ends of how much framework stands between you and the HTML. Vaadin gives you a component model and hides the markup. Thymeleaf with htmx gives you the markup and a few attributes that fetch fragments. This comparison is for Java teams choosing between them, with Vaadin Flow 24 and Spring Boot 4 on one side and Thymeleaf 3.1 with htmx 2 on the other.

How each one works

Vaadin builds a component tree in Java. The browser holds a thin client, and every interaction is a request that updates the tree on the server and sends back a diff. State lives on the server per browser tab, which the article on the server-side model explains in detail.

Thymeleaf with htmx returns HTML. A controller renders a template, and hx-get or hx-post attributes on elements ask for fragments that replace part of the page. The server holds no component state, so each request stands alone.

java
@GetMapping("/orders")
String orders(Model model) {
    model.addAttribute("orders", service.latest());
    return "orders :: table";   // a fragment, not the whole page
}
HTML
<button hx-get="/orders" hx-target="#list" hx-swap="innerHTML">Refresh</button>
<div id="list"></div>

The template name orders :: table selects a fragment, so the same file serves the full page on first load and the fragment on refresh. That reuse is what keeps htmx projects small. The click does not need any JavaScript written by you.

Comparison

VaadinThymeleaf plus htmx
You writeJavaJava and HTML templates
StateServer, per tabStateless by default
ComponentsGrid, charts, forms, dialogsYou assemble them or use CSS and JS libraries
ScalingMemory per sessionLike any web app, cacheable
Search indexingLimitedGood, pages are plain HTML
Custom lookTheming layerFull control of markup
Learning curveThe component APIHTML plus a few attributes

Where Vaadin is the better tool

Dense back-office screens are Vaadin's home ground: sortable lazy grids, editable forms with validation, dashboards with charts and dialogs. Building the same grid in templates means writing the paging, the sorting, the cell editing and the validation display yourself, or adopting a JavaScript grid and wiring it to endpoints. A developer who knows only Java can ship such a screen in an afternoon. The size of that saving is visible in a Vaadin CRUD screen, where the form binds to a bean with a few lines.

The price is the server-side session. Every open tab holds its component tree in memory, and a deploy that restarts the server can end user sessions unless you persist them. Sizing and the alternatives are covered in session memory.

Where Thymeleaf and htmx are better

Public sites, content pages and applications with a few interactive spots fit this stack. Pages are links, so they are indexable, bookmarkable and cacheable at a CDN, and the team works with HTML it can inspect in the browser. The back button behaves like the web. Anyone who has built a Spring MVC application already has most of the skills; the controller side is covered in Spring MVC controllers. The cost is that rich widgets come from outside: a date picker, a combo box and a sortable table are libraries you choose and style.

Testing

A Vaadin view is plain Java, so a unit test with the Vaadin testing library can construct it, fill a field and click a button without any browser, which is fast and stable. Template pages are checked with MockMvc and HTML assertions, and the htmx behaviour needs a browser test to prove the swap happens. Either way, keep a few end-to-end tests for the main flow; the details for Vaadin are in testing Vaadin views.

Team and hiring effects

A team of Java developers with no frontend specialist gets more from Vaadin, because the whole interface is in the language they already review. A team with at least one person comfortable in HTML and CSS gets more from Thymeleaf and htmx, because the design lives in templates that person can change without touching Java. Think about who will maintain the screens in two years. A Vaadin application with a custom theme still needs someone who can write CSS, and a template application needs someone who will keep the fragments organised.

What a migration between them costs

Moving from Thymeleaf to Vaadin means rewriting every template as Java components, so it is only worth doing for screens that were hard to build in HTML. Moving from Vaadin to Thymeleaf means rebuilding the grids and forms by hand and giving up server push. The service and repository layers survive both moves, which is why you should keep business logic out of views in either stack. A useful test: if a view class imports a repository, a refactor is going to be expensive.

Mixed setups are possible. A Spring Boot application can serve public pages with Thymeleaf and an authenticated back office with Vaadin, each under its own path prefix, sharing the same services. That split gives search engines their plain HTML and gives staff their grids, and it keeps Vaadin's session memory away from anonymous traffic. The two stacks then need separate security configuration for each prefix.

Latency and the user's connection

htmx replaces fragments over normal HTTP, so a slow link feels like a slow website: each click is a request. Vaadin keeps a connection open and sends small diffs, which feels quicker on a good network and degrades badly when the connection drops, since the client must resynchronise. Test both on a throttled link before deciding for users who work in poor reception.

Where this comparison stops

If the team already has React or TypeScript specialists and the interface must feel like a product, neither server framework is the obvious choice. See Vaadin versus React for that decision. If the application is for internal staff with no public pages, Vaadin's weaknesses mostly disappear. The projects are documented at htmx.org and in the Thymeleaf documentation, and the risks of Vaadin are laid out in when not to use Vaadin.

Also inSpring MVC
Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.