AO Fluent HTML

project: alphamanagement: previewpackaging: developmental
java: >= 11semantic versioning: 2.0.0license: LGPL v3

BuildMaven CentralQuality Gate StatusLines of Code
Reliability RatingSecurity RatingMaintainability RatingCoverage

Fluent Java DSL for high-performance HTML generation.



We have a lot of legacy servlet-based code that directly writes HTML as strings. This technique is both tedious and error-prone. We've been refactoring code to support HTML 5, and now is a good time to clean this up without radically rewriting everything.


  • Supports HTML 4.01, XHTML 1.0, HTML 5 and XHTML 5.
  • Supports both SGML and XML serializations.
  • Fluent API.
  • Also supports lambda element content, which makes it easier to code and debug than a strict fluent-only approach.
  • Context-aware compiler and code assistance through extensive use of the interface hierachy along with bounded self-referential generics.
  • Optimized code assistance through method deprecation, such as global attributes only being activated on expected elements.
  • Everything is encoded and safe by default, with unsafe(…) methods allowing raw output.
  • Optional automatic newline and tab indentation.
  • Optimized streaming implementation, including attributes.
  • Integrates with AO in-context translation tools.
  • Stupid fast (TODO: benchmark).
  • Separate module for use in a Servlet environment.


Not all tags and attributes are implemented. We are implementing as we go. A full implementation of all tags and attributes would probably be best achieved with code generation. This project will remain below version 1.0.0 until it has a reasonably complete implementation.

Evaluated Alternatives


HtmlFlow is a Java DSL to write typesafe HTML documents in a fluent style. It is very close to what we want. We may look into integrating our unique needs with their implementation. At this time, however, we still require support for XHTML 1.0, HTML 4, and XHTML 5. This, along with interoperability with our other projects, is steering us toward our own implementation.