1001Ferramentas
🔄Converters

HTML to HAML Converter

Convert HTML into the indented HAML syntax, with no closing tags and shorthand class and id syntax. Paste your HTML and get HAML — great for Ruby on Rails views.

Para HTML bem-formado. Não cobre <script>/<style> com conteúdo nem tags mal-fechadas.

Cada elemento começa com %. <p>Olá</p> vira %p Olá.

Use shorthand: %div.classe#id. Aninhe por indentação (2 espaços).

Atributos: %a{href: "/x", target: "_blank"} link.

Paste HTML, get indented HAML back

You inherited a Rails view full of angle brackets and the team writes HAML now. Converting by hand is dull work, and dull work is exactly where the indentation slips and quietly reparents half the markup. Paste the HTML into the top box and the indented version shows up below, with %tag lines, attributes in braces and no closing tags to keep track of.

Conversion runs through a small hand-written parser built on regular expressions, with no DOM involved. It knows the void elements (img, br, input, meta and friends) and never opens a block for them, turns HTML comments into slash lines, and applies the div shorthand, so a div carrying a class collapses to .card. Attributes become a hash: a link with href comes out as %a{href: "/x"} link.

It expects well-formed markup. Unclosed tags, the contents of script or style, and CDATA blocks sit outside what the parser handles. Text nodes are trimmed, so a paragraph with bold text in the middle becomes three lines and loses the space between words; stitch those back by hand. Boolean attributes such as required arrive with an empty string value, and the doctype passes through as literal text, so swap it for !!!. It converts in your browser.

Frequently asked questions

Does it understand ERB or Ruby?
No, it reads HTML. ERB blocks are treated as loose text and pass straight through, so you slot those tags back into the HAML lines afterwards.
Does deep nesting survive?
Yes. The tree is built from opening and closing tags and every level gets two spaces of indentation, as long as the HTML is well formed.
Can it go from HAML back to HTML?
No, this one only goes HTML to HAML. The reverse needs the HAML compiler itself, which runs in Ruby.

Related Tools