
HAML stands for HTML Abstraction Markup Language.
It is a templating language used to write clean, readable, and fast HTML code.
HAML was created to make HTML simpler and more elegant by removing the need for closing tags, repetitive syntax, and unnecessary code. It is mostly used in Ruby on Rails projects, but it can also be used with other web frameworks.
HAML helps developers write HTML in a structured, indentation-based format, which makes the code easier to read and maintain.
🧩 Purpose of HAML
- To simplify HTML coding.
- To make templates cleaner and more readable.
- To reduce the chances of syntax errors.
- To increase development speed by writing less code.
⚙️ Basic Example
🔹 HTML Code:
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1>Welcome to HAML</h1>
<p>This is a simple HTML example.</p>
</body>
</html>
🔹 Equivalent HAML Code:
!!!
%html
%head
%title My Page
%body
%h1 Welcome to HAML
%p This is a simple HTML example.
✅ Explanation:
- No need for closing tags (
</h1>
or</p>
). - Indentation (spaces) defines hierarchy.
%
is used before tags.- Content is written directly after the tag name.
🌟 Key Features of HAML
- Clean and indentation-based syntax (no closing tags).
- Faster and less repetitive than HTML.
- Automatically generates well-formatted HTML.
- Easy to embed Ruby code (in Rails).
- Helps maintain readable templates.
🔑 Advantages of HAML
- Reduces HTML code size.
- Easier to debug and maintain.
- Prevents unclosed tags and messy structure.
- Integrates seamlessly with Ruby on Rails.
⚔️ Difference Between HTML and HAML
Feature | HTML | HAML |
---|---|---|
Full Form | HyperText Markup Language | HTML Abstraction Markup Language |
Syntax Type | Tag-based | Indentation-based |
Closing Tags | Required | Not required |
Readability | Verbose | Clean and simple |
Used With | All web frameworks | Commonly with Ruby on Rails |