ClojureScript Coding Style Guide

Back to SIG ClojureScript Tutorials

Widely Accepted Style Norms

Before reading further, please visit the Clojure Coding Style guide page as any style norms in Clojure also apply to ClojureScript.

Clojure Coding Style Guide

SIG-specific Style Practices

The preferred order for Hiccup elements is as follows:

[:input {:id
         :class
         :style
         :any-other-keys
         :on-change}]

We decide to alphabetize any style tags:

{:style {:background-color "white"
         :border           "1px solid"
         :border-color     "brown"
         :border-radius    "2px"
         :font-family      "inherit"
         :height           "1.75rem"
         :padding          ".25rem .5rem"}}

When aligning nested Hiccup elements, use one space for nested elements instead of two:

(defn foo []
  [:div {:style {:padding "0 .5rem"}}
   [:div {:style {:display "flex"}}
    [:h1 "Happy Hacking!"]
    [:p "Hello World!"]]])