FreeMarker vs. Thymeleaf: Trade-offs

I recently had the chance to evaluate (and honestly, try) both Thymeleaf and FreeMarker for Zeario.

To be honest, I started with Thymeleaf (as it’s the most compelling option). Later, I switched to FreeMarker.


I worked a lot with PHP, Rails, and ASP.NET (MVC3+ with Razor). One thing all three of these platforms have in common is their allowance of extreme obsession over the HTML output. You can control each and every character of the final rendered HTML that comes out.

I like that. It allows you to easily configure and flex your application (CSS can be hell when you can’t even control the HTML), and it allows you to write clean, simple, and concise HTML.

That, in my opinion, is why FreeMarker is “better” than Thymeleaf. It takes you away from verbose XHTML declarations for every view, and allows you to write just the pieces that need to be plugged into your template layout.

Here’s a summary of places that I saw FreeMarker “win”:

  • Conditional Output: If I want to display something on a certain condition, in Thymeleaf, I need to wrap that content in a DIV tag with a conditional on it. In FreeMarker, I can just write the condition out; the HTML stays smaller.
  • Writing Text: In PHP, writing text is really easy: you just echo it out. In Thymeleaf, you need to put it in a tag (like a span element) with th:text (or th:utext for unicode). In FreeMarker, you can just write out your text; no additional tag required.
  • Bare-Bones Sections: Both technologies allow you to create a layout with sections, and define markup for that particular section on a particular page. In Thymeleaf, even the section declaration requires a bunch of XHTML markup; in FreeMarker, you only write exactly the HTML you display out. Simple and efficient.

This is a summary of why I chose FreeMarker over Thymeleaf, as an HTML maniac. It fits my needs quite well, and I’m happy with it. I hope it will serve me well in the future (and I have no qualms with switching over to something that works better if such a thing exists).

5 thoughts on “FreeMarker vs. Thymeleaf: Trade-offs

  1. Hmm, sounds like a Perl vs Python sort of debate

    > I chose FreeMarker over Thymeleaf, as an HTML maniac… in FreeMarker, you only write exactly the HTML you display out

    I prefer to apply the rigour of XHTML to ‘concise HTML’ – polylot HTML

    > CSS can be hell

    Maybe less concise HTML is saving me some pain ;-)

    > If I want to display something on a certain condition, in Thymeleaf, I need to wrap that content in a DIV tag with a conditional on it.


    > writing text is really easy

    I find wrapping it in semantic tags acts as a kind of editorial control.

    FWIW I used to work on a large application that used XSLT to generate the front-end. Now that had ‘verbose XHTML declarations’. I haven’t tried FreeMarker. If I hit the wall with Thymeleaf I’ll have a look.


    1. XHTML is dead for a while now. HTML5 does not require XML well-formedness. In my world, we have dedicated resource for front end and back end dev and our front end devs would not tolerate any amount of HTML being inserted.

  2. Your point about conditional output is outdated — Thymeleaf now has conditional blocks that don’t require any extra markup. See here:

    They fixed your second point, too — you can just echo out variables inline now:

    As for your third point, the Thymeleaf’s devs are at least trying to move it towards HTML5, though it’s built around and XML processor at its core. The markup for creating a layout file doesn’t look that heavy to me — it’s just a generic page, with DOCTYPE, HTML, and BODY elements.

  3. Another nice thing about thymeleaf is natural templating. (*). I don’t think Freemarker can support that…

    * Wikipedia: Natural templates = the template can be a document as valid as the final result, the engine syntax doesn’t break the document’s structure

  4. I really don’t understand why the world needed Thymeleaf. At what point is going to solidly exceed Freemarker in any respect? Is there some plan for it have miraculous new features? Freemarker already worked fine. JSP offered a distinctly different approach (at least in terms of implementation) to set it apart. We already have Velocity, StringTemplate and a Mustache port as well. Seems like Thymeleaf is entirely unnecessary to me.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>