Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

50 lines (36 sloc) 1.31 KB


Hiccup is a library for representing HTML in Clojure. It uses vectors to represent tags, and maps to represent a tag's attributes.


Here is a basic example of Hiccup syntax:

user=> (use 'hiccup.core)
user=> (html [:span {:class "foo"} "bar"])
"<span class=\"foo\">bar</span>"

The first element of the vector is used as the tag name. The second attribute can optionally be a map, in which case it is used to supply the tag's attributes. Every other element is considered part of the tag's body.

Hiccup is intelligent enough to render different HTML tags in different ways, in order to accommodate browser quirks:

user=> (html [:script])
user=> (html [:p])
"<p />"

And provides a CSS-like shortcut for denoting id and class attributes:

user=> (html [ "bang"])
"<div id=\"foo\" class=\"bar baz\">bang</div>"

If the body of the tag is a seq, its contents will be expanded out into the tag body. This makes working with forms like map and for more convenient:

user=> (html [:ul
               (for [x (range 1 4)]
                 [:li x])])


Jump to Line
Something went wrong with that request. Please try again.