Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Hiccup is a fast Clojure library for representing and rendering HTML using vectors and maps.
Hiccup is a Clojure library that renders HTML from vector and map data structures, giving developers a composable, programmatic way to generate markup without a separate template language.
Hiccup is a library for representing HTML in Clojure, created by James Reeves and distributed under the Eclipse Public License. It takes Clojure vectors (for elements) and maps (for attributes) as input and produces HTML strings as output, with automatic string escaping in version 2.0.0. The library runs on any Clojure implementation and integrates with standard Clojure build tools via deps.edn or Leiningen. It is actively maintained and documented through a wiki and API docs.
[:span {:class "foo"} "bar"] renders as <span class="foo">bar</span>.[:div#foo.bar.baz "bang"] renders as <div id="foo" class="bar baz">bang</div>, reducing attribute boilerplate.hiccup2.core/raw function opts out for trusted content like a doctype.(for [x (range 1 4)] [:li x]) directly.[:script] becomes <script></script> while [:p] becomes <p />, matching browser expectations.hiccup.core vs hiccup2.core), enabling incremental migration.for and map to generate tables, lists, and other repeated elements.html macro in a REPL; the returned RawString nests cleanly in larger html calls.Hiccup is open source and distributed under the Eclipse Public License, version 1.0 or later, so you can use it in commercial projects without licensing fees.
Hiccup 1 does not escape strings by default; you must wrap untrusted text with the h function. Hiccup 2 escapes all strings automatically and returns a RawString from the html macro, which enables nesting. The two versions use different namespaces (hiccup.core vs hiccup2.core), so they can coexist.
Use hiccup2.core/raw to bypass escaping for trusted content, such as a doctype declaration or an inline <em> tag. For example, (h/raw "<!DOCTYPE html>") emits the literal string.
Hiccup is written in Clojure and works anywhere Clojure runs, including ClojureScript projects, making it suitable for both server-side and client-side HTML generation.
