From Wikipedia, the free encyclopedia
Jump to: navigation, search
Haml 1-5 logo.png
Developer(s) Norman Clarke, Natalie Weizenbaum, Hampton Catlin
Stable release 4.0.7 / August 10, 2015 (2015-08-10)
Written in Ruby
Operating system Cross-platform
Type Template engine
License MIT License
Website haml.info

Haml (HTML Abstraction Markup Language) is a lightweight markup language that is used to describe the HTML of a web document. Haml functions as a replacement for inline page templating systems such as PHP, eRuby, and ASP. By directly describing the layout of a document Haml avoids the need for explicitly coding HTML into the template.

Haml's equivalent for CSS is Sass.


HAML was created initially by Hampton Catlin with the goal of satisfing the following core principles:[1]

  • Markup should be beautiful
  • Markup should be DRY
  • Markup should be well-indented
  • HTML structure should be clear


Note: This is a simple preview example and may not reflect the current version of the language.

%html{ :xmlns => "http://www.w3.org/1999/xhtml", :lang => "en", "xml:lang" => "en"}
    %title BoBlog
    %meta{"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8"}
    %link{"rel" => "stylesheet", "href" => "main.css", "type" => "text/css"}
      %h1 BoBlog
      %h2 Bob's Blog
      - @entries.each do |entry|
          %h3.title= entry.title
          %p.date= entry.posted.strftime("%A, %B %d, %Y")
          %p.body= entry.body
        All content copyright © Bob

The above Haml would produce this XHTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
    <meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
    <link href="/stylesheets/main.css" media="screen" rel="Stylesheet" type="text/css" />
    <div id='header'>
      <h2>Bob's Blog</h2>
    <div id='content'>
      <div class='entry'>
        <h3 class='title'>Halloween</h3>
        <p class='date'>Tuesday, October 31, 2006</p>
        <p class='body'>
          Happy Halloween, glorious readers! I'm going to a party this evening... I'm very excited.
      <div class='entry'>
        <h3 class='title'>New Rails Templating Engine</h3>
        <p class='date'>Friday, August 11, 2006</p>
        <p class='body'>
          There's a very cool new Templating Engine out for Ruby on Rails. It's called Haml.
    <div id='footer'>
        All content copyright © Bob


The official implementation of Haml has been built for Ruby with plugins for Ruby on Rails and Merb, but the Ruby implementation also functions independently.

There are also implementations in other languages:


Haml was created in May 2006 by Hampton Catlin. Shortly thereafter Natalie Weizenbaum became the primary developer and architect of the primary implementation of Haml in Ruby. In April 2012 Norman Clarke who had authored the official Haml Specification and led the development of Haml for Lua took over maintainership of the project.

See also[edit]


External links[edit]