HTML Formatter

Format and beautify HTML markup with sensible defaults. Everything runs in your browser, so your data never leaves the page.

About this HTML formatter

This is a free online HTML formatter. Paste any HTML document (or fragment) into the input panel and you'll get a cleanly indented, readable version in the output panel. Block-level elements get their own line, inline elements stay inline, and the existing structure of the markup is preserved.

Features

  • Format HTML with 2 spaces, 4 spaces, or tab indentation.
  • Wrap long lines at a chosen column, or leave them unwrapped.
  • Embedded <script> and <style> blocks are formatted as JavaScript and CSS.
  • Preserve attributes, comments, conditional comments, and doctypes.
  • Copy the result or download it as an .html file.

How it works

The tool uses the open source js-beautify library, loaded into your browser on first use. It tokenizes the markup, understands which elements are block versus inline, and pretty-prints accordingly.

Privacy

Your HTML never leaves your browser. The whole tool runs locally as JavaScript on this page, so you can safely paste production templates, internal documents, or anything else without it touching a server.

Frequently asked questions

Does this tool send my HTML anywhere?
No. Formatting happens entirely in your browser. The js-beautify library is fetched once from a public CDN, but your HTML text is never uploaded.
Does it validate the HTML?
No. The formatter only changes whitespace, it does not check whether your tags are valid or correctly nested. Use the W3C Markup Validator for proper validation.
Will my markup be changed beyond whitespace?
In normal use, no. The formatter only adjusts indentation and line breaks. It does not rewrite tag names, attribute values, character references, or text content.
What happens to <script> and <style> blocks?
Their contents are passed through the JavaScript and CSS beautifiers, so inline scripts and stylesheets get the same indent treatment as the surrounding markup.