# Haml [![Gem Version](https://badge.fury.io/rb/haml.svg)](http://rubygems.org/gems/haml) [![Build Status](https://travis-ci.org/haml/haml.svg?branch=master)](http://travis-ci.org/haml/haml) [![Code Climate](http://img.shields.io/codeclimate/github/haml/haml.svg)](https://codeclimate.com/github/haml/haml) [![Coverage Status](http://img.shields.io/coveralls/haml/haml.svg)](https://coveralls.io/r/haml/haml) [![Inline docs](http://inch-ci.org/github/haml/haml.png)](http://inch-ci.org/github/haml/haml) Haml is a templating engine for HTML. It's designed to make it both easier and more pleasant to write HTML documents, by eliminating redundancy, reflecting the underlying structure that the document represents, and providing an elegant syntax that's both powerful and easy to understand. ## Basic Usage Haml can be used from the command line or as part of a Ruby web framework. The first step is to install the gem: ~~~sh gem install haml ~~~ After you write some Haml, you can run ~~~sh haml document.haml ~~~ to compile it to HTML. For more information on these commands, check out ~~~sh haml --help ~~~ To use Haml programatically, check out the [YARD documentation](http://haml.info/docs/yardoc/). ## Using Haml with Rails To use Haml with Rails, simply add Haml to your Gemfile and run `bundle`. ~~~ruby gem 'haml' ~~~ Haml 4.1 requires an actively maintained version of Rails (version 3.2 or later). If you are using Rails 3.0 or 3.1, you should use Haml version 4.0.x: ~~~ruby gem 'haml', '~> 4.0.5' ~~~ If you'd like to replace Rails's Erb-based generators with Haml, add [haml-rails](https://github.com/indirect/haml-rails) to your Gemfile as well. ## Formatting The most basic element of Haml is a shorthand for creating HTML: ~~~haml %tagname{:attr1 => 'value1', :attr2 => 'value2'} Contents ~~~ No end-tag is needed; Haml handles that automatically. If you prefer HTML-style attributes, you can also use: ~~~haml %tagname(attr1='value1' attr2='value2') Contents ~~~ Adding `class` and `id` attributes is even easier. Haml uses the same syntax as the CSS that styles the document: ~~~haml %tagname#id.class ~~~ In fact, when you're using the `