Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
A macro-based HTML and XML templating library for Rust.
Horrorshow is a Rust templating library that uses macros to build HTML and XML at compile time, offering type-safe and dependency-light output for Rust projects.
Horrorshow is a macro-based HTML and XML templating library for stable Rust (requires Rust 1.48 or newer). It accepts Rust source code containing the html! macro—along with helper macros for loops, conditionals, and closures—and produces a string of rendered HTML or XML. The crate is distributed via crates.io, and its API is documented on docs.rs. It is designed to degrade gracefully: when compiled without std, Template::write_to_io() is removed and errors become ToString-compatible; when compiled without alloc, rendering is limited to write_to_fmt() and errors are limited to static &str values.
html! { html { head { title : "..." } } }; the compiler validates tag structure at compile time.: is HTML-escaped; use Raw(...) to emit unescaped content deliberately.@ for, @ if, and closures directly inside the template to generate repeated or conditional markup.core (no allocation) or with alloc but no std, with corresponding reductions in available Template methods.Template trait provides write_to_fmt(), into_string(), write_to_string(), and write_to_io(), depending on enabled features.helper::doctype module outputs standard DOCTYPE declarations, e.g., doctype::HTML for HTML5.no_std targets who need minimal HTML/XML generation with no allocation overhead.doctype::HTML plus tags like html, head, body, h1, p, ol, and br to produce a full page, as shown in the README example.@ for i in 0..10 to emit repeating elements, with attribute expressions like first? = (i == 0) for conditional attributes.|tmpl| { tmpl << "..." } blocks to insert output procedurally from Rust code.Horrorshow's macros expand into Rust expressions that implement the Template trait. The rendered output is written to a fmt::Write implementation, allowing you to produce a String via format!("{}", html!{ ... }) or write directly to a Write target. The example in the README demonstrates the entire flow: a macro invocation becomes a string, which is then compared with an expected HTML string in a test.
Yes, it is a publicly available crate on crates.io and is open source. No pricing tiers or paid features are listed in the repository.
Horrorshow is compatible with stable Rust, with a minimum supported version of Rust 1.48. It is not tied to any nightly features.
Yes. With the std feature disabled, it compiles without the standard library. If alloc is also disabled, only write_to_fmt() is available and templates may only emit static string errors.
No. Horrorshow only generates HTML/XML strings from Rust code. It does not include JavaScript, CSS, or client-side behavior; you pair it with your own HTTP layer or embed it in a larger application.
Other Rust templating libraries include maud, which also uses an inline macro syntax, and askama, which compiles template files with a syntax inspired by Jinja2. Each has different trade-offs in terms of syntax and compile-time checking.
