Thymeleaf Attributes

Learn how to use Thymeleaf expressions inside Thymeleaf attributes.

The Thymeleaf expressions we just saw can be used inside Thymeleaf attributes like the th:text attribute. This lesson will go over the most important attributes.

Element text content

The th:text attribute will place the result of the expression inside the tag it is declared on.

For example, assuming the username variable contains “Jane”:

<div th:text="${username}">Bob</div>

will render as:

<div>Jane</div>

Element id attribute

Similarly, the th:id attribute will add an id attribute.

 ...