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
FeatureHTMLHAML
Full FormHyperText Markup LanguageHTML Abstraction Markup Language
Syntax TypeTag-basedIndentation-based
Closing TagsRequiredNot required
ReadabilityVerboseClean and simple
Used WithAll web frameworksCommonly with Ruby on Rails

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *