Search code examples
thymeleaf

How to escape single quote (') in Thymeleaf


<h1 th:text="${'What\'s up?'}"></h1>

I want this to output

<h1>What's up?</h1>

But I get an TemplateInputException. I have tried with HTML entity but it fails the same.


Solution

  • Double single quote. Like this:

    <h1 th:text="${'What''s up?'}" />