HTML Formatter

Paste HTML that is minified, copied from a page source or badly indented, and get it back with one element per line and consistent indentation. Short elements such as list items stay on one line, inline tags like <b> and <a> stay inside their text, and the content of <pre>, <textarea> and <script> is never rewritten. It formats as you type, in your browser.

Language
Indent

<li>One</li> instead of three lines

33 lines

Formatting runs in your browser. What you type never leaves this device.

Features

  • Indent with 2 spaces, 4 spaces or tabs

  • Block elements on their own lines; inline tags such as <a>, <b> and <span> stay with their text

  • <pre> and <textarea> content kept exactly, <script> code re-indented as a block without changing a character inside it

  • CSS inside <style> tags formatted with the same rules as our CSS formatter

  • Comments and the doctype kept; extra spaces inside tags removed while attribute values stay untouched

  • Copy the result or download it as an .html file

When an HTML formatter helps

Reading minified page source

View source on most sites shows one long line. Paste it here to see the structure of the head, the navigation and the content blocks.

Cleaning up email templates

HTML exported from email builders is often deeply nested tables on a few lines. Formatting it makes it possible to find and edit the row you need.

Code reviews and diffs

Format both versions of a template the same way before comparing them in the Diff Checker, so only real changes show up.

Learning HTML

Indented markup shows which element sits inside which, which makes a copied snippet much easier to understand and adapt.

How the formatter treats your HTML

What changes and what does not

  • Whitespace between elements is replaced by line breaks and indentation. Whitespace inside text is collapsed to single spaces, the same way a browser displays it.
  • Inside <pre> and <textarea>, spaces and line breaks are meaningful, so that content is kept exactly as written.
  • Script code is moved to the new indentation level as a block; its own relative indentation and every character are kept.
  • Attribute values are never changed, even if they contain several spaces.

Short elements on one line

With "Keep short elements on one line" on, an element whose content is only text and inline tags stays on one line when it fits within about 100 characters, so <li>One</li> does not become three lines. Turn it off to put every element's content on its own line.

Limits

The formatter re-indents; it does not validate or repair markup. Unclosed or mismatched tags are formatted as they are, which can make the indentation drift after the mistake. Long lists of attributes stay on the tag's line. To make HTML smaller rather than readable, use the HTML Minifier.

HTML Formatter - FAQ