HTML Formatter & Beautifier

Paste HTML source and reprint the tags with the indent you choose. The markup is not inserted into the page, so scripts do not run.

Use this tool

The file is read on this page and is not uploaded.

Result

The result appears in this panel after you run the tool.

About this tool

Beautify and pretty-print mean the same reprint: tags, attributes, quoted values, and comments stay in the source, and nested elements are indented. The formatter walks the text. It does not parse the markup into the document, so a pasted script element is not executed, an img address is not requested, and an event-handler attribute is not run.

Use it to read a minified snippet, to line up a template before you diff it, or to check that a fragment is balanced enough to indent. Void elements such as br and img do not gain children. Layout whitespace between tags is the indent you chose. Text inside a tag keeps its internal spaces. The bytes inside script, style, pre, and textarea are copied unchanged, including a broken script if that is what you pasted.

A successful format is not a validity badge. The tool does not fix missing tags, and it does not claim to match a browser’s error recovery. The result is still HTML source, and it stays in this browser.

How to use it

  1. Paste HTML source, or choose a local file. The file is read on this page and is not uploaded.
  2. Choose an indent, then Format HTML. Ctrl+Enter or Cmd+Enter does the same thing from the box.
  3. Copy or download the reprint. A mismatched or unclosed tag is reported instead of being repaired.

Limitations

Tokens and indents, never a live document

The scanner never builds a live document

Markup is tokenized as text, then indented. The scanner does not hand the paste to the DOM, so a script element is not executed, an image address is not fetched, and an event-handler attribute is not fired. That choice is why a sample can contain a script whose body says to keep a brace: the body is copied, not evaluated. Void tags such as br, img, input, meta, and the rest of that set do not expect a close tag. A tag that already ends with a slash is treated as finished. script, style, pre, and textarea are raw: everything until the matching close tag is copied with its original characters, including spaces you would not want reflowed.

Ordinary text is treated more roughly. Space at the two ends of a text run is removed. A line break inside that run, plus any indent beside it, becomes one space. Spaces that sit in the middle of a line and are not beside a break stay as they are. Comments stay intact, and so do declarations and processing instructions that start with an exclamation mark or a question mark. A byte-order mark at the front of the file is dropped before scanning.

Mismatches are reported, not repaired

An open tag that never finds its greater-than sign fails, including the case where a quote inside the tag is never closed. A comment that never finds its end marker fails. A close tag whose name does not match the open tag currently on the stack fails, and the message names the tag that was expected. A file that ends while a tag is still open fails. The scanner will not invent the missing close tag, reorder attributes, or rewrite a broken name into a legal one. Indent size is two spaces, four spaces, or a tab, applied to the depth of the open tags. It is not a check that the names are allowed in a particular HTML revision.

What the indent pass leaves alone

Attribute order inside a tag is the order in the source tag text, because the whole tag is copied as one token. Classes, inline styles, and unknown attributes are not interpreted. A minifier that pulls tags together and deletes comments is a different page. Markdown conversion is a different page too. Use this formatter when the markup is already well enough nested to walk, and the goal is a readable indent.

Privacy

Your HTML is processed in your browser and is not uploaded to UtilChain. File names, source text, and results are not sent to analytics.