What Is .erb

Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.

Last updated: April 10, 2026

Quick Answer: .erb (Embedded Ruby) is a templating language that allows Ruby code to be embedded within HTML and other text files, primarily used in Ruby on Rails applications since 2004. Files use the .erb extension and process server-side using delimiters like <% %> for code execution and <%= %> for output. It remains the default template engine for Rails, used in approximately 70% of active Rails applications.

Key Facts

Overview

.erb stands for Embedded Ruby and is a templating language that allows developers to embed Ruby code directly within text files, most commonly HTML documents. Originally included in Ruby's standard library and later adopted as the default template engine for Ruby on Rails in 2004, ERB remains one of the most popular templating systems in web development. ERB templates use the .erb file extension and enable the seamless integration of dynamic content with static HTML markup.

The power of ERB lies in its simplicity and deep integration with the Ruby language. Rather than requiring developers to learn a specialized templating syntax, ERB allows them to use pure Ruby code within specific delimiters to control how content is rendered. This approach means developers familiar with Ruby can immediately start writing templates without any additional learning curve. ERB templates are processed on the server side before being sent to the client's browser as plain HTML, which keeps application logic secure and separated from client-side code.

How It Works

ERB processes template files through a series of steps that transform embedded Ruby code into final HTML output. Here are the key mechanisms:

Key Comparisons

ERB is one of several templating engines available for Rails developers. Here's how it compares to popular alternatives:

FeatureERBHamlSlim
Learning CurveLow (pure Ruby syntax)Medium (custom syntax required)Medium (minimal syntax)
Performance SpeedFastModerate (slower compilation)Fast
Server CompatibilityRails, Ruby, extensiveRails, Ruby, limitedRails, Ruby, growing
Market Share~70% of Rails applications~15% of Rails applications~10% of Rails applications
HTML Output SafetyAutomatic escaping (Rails 4+)Automatic escapingAutomatic escaping
Readability for Ruby DevsExcellent (native Ruby)Good (distinct syntax)Good (minimal markup)

Why It Matters

ERB remains the default choice for Rails template rendering because it provides an optimal balance of simplicity, power, and security. While other templating engines like Haml and Slim offer alternative syntax preferences and some stylistic advantages, ERB's combination of native Ruby syntax, widespread adoption across the Rails ecosystem, and comprehensive Rails integration makes it the most practical choice for the vast majority of Rails developers. Understanding ERB templating is fundamental to becoming proficient with Ruby on Rails web development.

Sources

  1. Ruby on Rails Action View OverviewCC-BY-4.0
  2. Ruby Standard Library: ERB DocumentationRuby License
  3. Ruby on Rails Layouts and Rendering GuideCC-BY-4.0

Missing an answer?

Suggest a question and we'll generate an answer for it.