N
The Global Insight

What is Thymeleaf in Java

Author

Andrew Campbell

Updated on April 11, 2026

Thymeleaf is a Java template engine for processing and creating HTML, XML, JavaScript, CSS, and text. In this article, we will discuss how to use Thymeleaf with Spring along with some basic use cases in the view layer of a Spring MVC application.

What is Thymeleaf used for?

Thymeleaf is a Java-based library used to create a web application. It provides a good support for serving a XHTML/HTML5 in web applications. In this chapter, you will learn in detail about Thymeleaf.

Is Thymeleaf better than JSP?

Thymeleaf is way better in my opinion because it have good underlying priciples and exploits natural behaviour of browsers. Jsp makes html hard to read, it becomes weird mixture of html and java code which makes a lot of problems in comunication between designer – developer.

Is Thymeleaf a frontend?

Thymeleaf is a Java-based template engine that allows to build dynamic pages using templates written in XML, XHTML or HTML. The engine provides a very pleasent way to inject logic into the templates. … The engine allows a parallel work of the backend and frontend developers on the same view.

Is Thymeleaf part of spring?

Thymeleaf offers a set of Spring integrations that allow you to use it as a fully-featured substitute for JSP in Spring MVC applications.

How do I install Thymeleaf?

  1. In the Settings/Preferences dialog ( Ctrl+Alt+S ) select Plugins | Installed.
  2. Make sure that the checkbox next to the Thymeleaf plugin is selected. Otherwise, select the checkbox to enable the plugin.
  3. Apply the changes and close the dialog. Restart the IDE if prompted.

What is Thymeleaf?

Thymeleaf is a Java library. It is an XML/XHTML/HTML5 template engine able to apply a set of transformations to template files in order to display data and/or text produced by your applications. … The main goal of Thymeleaf is to provide an elegant and well-formed way of creating templates.

Is Thymeleaf backend?

Thymeleaf is just that. It allows for natural templating, can do complex processing and lets us easily define custom dialects. On top of that, Thymeleaf facilitates the collaboration of both front end and back end developers on the same template file, greatly increasing productivity.

Is Thymeleaf open source?

Thymeleaf is open-source software, licensed under the Apache License 2.0.

Is Thymeleaf better than angular?

The most important difference is reusability of back-end services. when you use thymeleaf, you are returning string fragments/pages into client side, while if you use angular, you can return objects (json response) into client side, so that can be used by different clients (web, mobile, etc).

Article first time published on

Can we use Thymeleaf with JSP in spring boot?

Consider a spring boot application that already using thymeleaf and there is a need in your application to have JSP page for processing few data in JSP page. To use JSP along with Thymeleaf we need to configure InternalResourceViewResolver bean along with addition few dependencies.

Does Thymeleaf work with JSP?

Thymeleaf is packed with several dialects, and takes the place of JSP in the default stack provided by Spring. … This will give the page access to use the family of “th” attributes in html tags, thereby having access to the features available in the basic Thymeleaf dialect.

How do you add Thymeleaf in html?

  1. Place both pages under the resources folder, something like /resources/one. html, /resources/two. html.
  2. Include two. html in one. html by adding this line in one. html: <div th:insert=”two :: two”></div>
  3. Include this bit of code in two. html just after the <body> tag: <div th:fragment=”two”>

What is th object Thymeleaf?

The th:action is used to provide the form action URL and th:object is used to specify an object to which the submitted form data will be bound. Individual fields are mapped using the th:field=”*{name}” attribute, where the name is the matching property of the object.

How do I configure Thymeleaf?

1.1. Spring Boot will provide auto-configuration for Thymeleaf. Add spring-boot-starter-thymeleaf dependency in pom. xml to enable this auto-configuration. No other configurations required, Spring Boot will inject all required configuration to work with Thymeleaf.

Do companies use Thymeleaf?

22 companies reportedly use Thymeleaf in their tech stacks, including Craftbase, Tech-Stack, and immowelt Hamburg GmbH.

Can I use Javascript in Thymeleaf?

Thymeleaf provides javascript mode using th:inline=”javascript”. Find the syntax below. Here Thymeleaf fetches user name from Servlet session in our example.

Why Thymeleaf is used in spring boot?

It provides full integration with Spring Framework. It applies a set of transformations to template files in order to display data or text produced by the application. It is appropriate for serving XHTML/HTML5 in web applications. The goal of Thymeleaf is to provide a stylish and well-formed way of creating templates.

What is JSP page in Java?

JavaServer Pages (JSP) is a Java standard technology that enables you to write dynamic, data-driven pages for your Java web applications. JSP is built on top of the Java Servlet specification. The two technologies typically work together, especially in older Java web applications.

How do you spell Thymeleaf?

Thymeleaf is a modern server-side Java template engine for both web and standalone environments.

What is bean in spring?

A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. Otherwise, a bean is simply one of many objects in your application. Beans, and the dependencies among them, are reflected in the configuration metadata used by a container.

Is Thymeleaf server side rendering?

Thymeleaf is a serve-side template engine for Java. It has built-in support for Spring framework and is widely used in Spring based Projects. In fact, Spring Boot itself has been promoting thymeleaf via several thymeleaf based projects and examples in its blog.

Can Thymeleaf be used without spring?

Absolutely. Thymeleaf offers nice integration with Spring MVC through its SpringStandard dialect (included in the thymeleaf-spring3 , thymeleaf-spring4 and thymeleaf-spring5 packages), but Spring integration is completely optional and the Standard dialect is in fact meant to be used without Spring.

How do I submit a form to Thymeleaf?

  1. Choose either Gradle or Maven and the language you want to use. This guide assumes that you chose Java.
  2. Click Dependencies and select Spring Web and Thymeleaf.
  3. Click Generate.
  4. Download the resulting ZIP file, which is an archive of a web application that is configured with your choices.

Can Springboot be used as frontend?

In that sense Spring also has an impact on frontend. However, it is not a “frontend framework” as such, it is a java framework and can be leveraged wherever java is used. Spring can use additional Frameworks like Thymeleaf, which is used in your example to provide a template HTML page.

Is react better or angular?

TechnologyAngularPerformanceSlower Performance – the “Real” DOM and bidirectional data binding process make Angular’s performance slower than React. However, it may change with the addition and improvement of Ivy, a new technology .

Should you learn Thymeleaf?

If you want traditional web application when any request should trigger a round trip to the server and reload the entire page then thymeleaf should be your option. And in that case your springboot backend controller will mostly configure with view resolver to resolve and render thymeleaf template at the server side.

How do I add bootstrap to Thymeleaf?

  1. Using bootstrap CSS CDN remote links.
  2. Downloading Bootstrap CSS file locally, add to project and finally add a file path to Thymeleaf template.

What is the difference between JSP and JSF?

JSF is a web-based application that is used to simplify the development integration of web-based user interfaces. While JSP is a Java-based technology used respectively in order to support software developers create dynamic web pages. JSP must be compiled in Java bytecode in order to work properly.

What is tiles in Spring MVC?

Apache Tiles is a template based, composite view framework: it allows to reuse page pieces across the application, keeping consistent look and feel. Page layouts in general contains several page-fragments like header,footer, menu & content.

What is used instead of JSP?

In the standard Java EE API, the only alternative to JSP is Facelets. As far now (2010) JSF is the only MVC framework which natively supports Facelets. Spring MVC supports out of the box only JSP, but it has a configurable view resolver which allows you to use Facelets anyway.