Description #
Thymeleaf is a modern server-side Java template engine used to generate HTML, XML, and other formats while preserving a natural template structure that works in browsers and IDEs.
History #
Thymeleaf was created by Daniel Fernández and released in 2011 as an alternative to JSP. It gained popularity in the Spring ecosystem and became the default template engine in Spring Boot.
Hello World Code #
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Hello</title>
</head>
<body>
<h1 th:text="'Hello, World!'">Placeholder</h1>
</body>
</html>
How to Run #
Option 1: Online
Run with Spring Boot using tools like:
https://start.spring.io/
Option 2: Local
Create a Spring Boot project with Thymeleaf:
spring init --dependencies=web,thymeleaf hello-thymeleaf
In a controller:
model.addAttribute("message", "Hello, World!");
return "index"; // index.html
In templates/index.html
:
<h1 th:text="${message}">Placeholder</h1>
Key Concepts #
- Uses HTML5-compatible syntax with custom
th:
attributes - Natural templates work in plain browsers (no breaking tags)
- Full support for loops, conditionals, fragment inclusion
- Tight integration with Spring MVC
- Variable expressions via
${}
and text/template processing - Supports HTML, XML, and even email templates
- Layout dialects and reusable fragments
- Context-aware escaping and internationalization
- Can run in offline mode (for static rendering)
- Lightweight and extensible via dialects
Try It Online #
https://start.spring.io/
(Local Java IDE required for testing)
Fun Facts #
- Thymeleaf was designed to be “natural templating,” meaning the files work with or without a backend engine.
- Often used in Spring Boot applications to render dynamic views.
- Supports powerful extensions like layout dialects and conditional inclusion.
Resources #
Official site
Docs or tutorial
GitHub or interpreter
Community or learning resources