This page is not available in every language. Missing translations are disabled in the language selector.

Quick reference

Haml Cheatsheet

A quick reference guide for Haml: doctypes, tags, classes, IDs, inline HTML attributes, Ruby evaluation, filters, and indentation rules.

· Published

Haml is a templating engine for HTML that uses whitespace indentation to produce clean, DRY markup.

Basics

Doctype

!!!
!!! 5
!!! Strict
!!! Frameset
!!! Mobile
!!! Basic

Tags & Structure

%p Hello World
%span
  Inner text

Classes & IDs

%div#content
  %p.highlighted Text content

/ Div is the default tag when omitted
.notice
  #login-box

Inline Attributes

Both hash syntaxes are supported:

%html{ "xml:lang" => "en", :lang => "en" }
%a{ :href => "/login", :title => "Sign in" }

/ HTML-style attributes syntax
%a(href="/login" title="Sign in")

Ruby Evaluation

= "Evaluated Ruby expression"
- [1, 2, 3].each do |num|
  %li= num

References

Related topics