Skip to content

Format ERB templates while preserving embedded Ruby delimiters and HTML structure without executing code.

Loading tool

About ERB Beautify / Minify

Format or minify Ruby on Rails ERB templates. Every <% %>, <%= %>, <%- %> and <%# %> tag is swapped for a placeholder while the surrounding HTML is indented with js-beautify, then restored, and HTML between ERB block openers (if, each ... do, etc.) and their end is indented to match. Ruby code is never executed or reformatted, and a check warns when the counts of <% and %> do not match.

Common uses

  • Re-indent a Rails view where HTML and control flow have drifted out of alignment.
  • Clean up a partial pasted from a code review or an old project before editing it.
  • Find an unterminated ERB tag by comparing <% and %> counts.
  • Minify an ERB template's HTML whitespace and comments while keeping the Ruby tags intact.

FAQ

What is ERB?
ERB (Embedded Ruby) is Ruby's templating system and the default view format in Ruby on Rails. <% %> runs Ruby code, <%= %> outputs its result, and <%# %> is a comment.
Does this formatter change my Ruby code?
No. ERB tags are protected with placeholders and restored verbatim; only the HTML structure and indentation around them change.