Format HTML

Format HTML elements, attributes, comments, and nested blocks for readable source.

freeworks offlinenothing uploaded
ToolHTML Formatter
Input
Output

How it works

Markup is tokenized and serialized with indentation around nested elements while raw-text and preformatted content remain protected. Formatting changes whitespace outside sensitive contexts.

  • Two-space indentation exposes DOM nesting.
  • One element per line suits review.

Worked example

Prettify minified HTML
Add proper indentation and line breaks to compressed HTML
Input
											<div><h1>Title</h1><p>Paragraph</p></div>
										
Output
												<div>
  <h1>
    Title
  </h1>
  <p>
    Paragraph
  </p>
</div>
											

When to use this

Template reviews, static-site builds, and captured markup formatting format HTML.

Edge cases

  • Whitespace in pre and textarea is significant.
  • Script strings can contain tag-looking characters.
  • Optional end tags make textual indentation ambiguous.

References