Skip to content

HTML Formatter

Beautify minified or messy HTML with one element per line and consistent 2-space indentation.

Runs in your browser Free, no sign-up
Loading tool workspace...

What is HTML Formatter?

This HTML formatter turns minified, generated or messy HTML into clean, consistently indented markup. Paste HTML copied from a CMS, a page source, an email template or a framework's output, and each element is placed on its own line with 2-space indentation per nesting level, so the structure of the document is easy to follow.

Formatted HTML is easier to review, debug and edit: you can see which elements are inside which, spot unclosed or misplaced tags, and paste clean markup into documentation or a code review.

How to use HTML Formatter

  1. Paste your HTML into the input panel.
  2. The formatted HTML appears in the output panel immediately.
  3. Review the nesting shown by the indentation.
  4. Copy or download the formatted markup.

Key features

  • One element per line with 2-space indentation
  • Consistent double-quoted attributes
  • Self-closing syntax for void elements
  • Keeps the doctype, comments, and script, style and pre contents
  • Uses the browser's HTML parser without running scripts
  • Copy or download the result
  • Runs entirely in your browser

Common use cases

  • Reading minified HTML from a page source or build output
  • Cleaning up HTML exported from a CMS or WYSIWYG editor
  • Reviewing email templates and generated markup
  • Preparing HTML snippets for documentation and tutorials
  • Spotting misnested elements in template output

Technical details & standards

The HTML is parsed with the browser's own HTML parser in an inert copy, where scripts and event handlers such as onerror never run, and written back out element by element with 2 spaces of indentation per level. Runs of whitespace in text collapse to one space, elements containing only text stay on one line, attribute values are written in double quotes, attributes such as disabled keep their short form, and void elements such as img, input, br, hr, meta and link are written in self-closing form (<br />).

Because the browser's parser is used, its error correction applies: unclosed tags are closed, and misnested elements are rearranged the way a browser would display them. A full page keeps its doctype and its html, head and body elements, and a snippet is formatted on its own. Comments are kept, and the contents of script, style, pre and textarea elements are written back exactly as they were.

Frequently asked questions

How do I format HTML code?

Paste the HTML into the input panel and the indented version appears instantly. Code editors also format HTML, for example with Prettier or VS Code's Format Document command (Shift+Alt+F).

Does the formatter keep the doctype and the html, head and body tags?

Yes. A full page keeps its <!DOCTYPE html> and its html, head and body elements. If the page has an <html> tag but no <head> or <body> tag, they are added, the same way a browser adds them when it reads the page.

Does formatting change how my page looks?

Usually not. Line breaks and indentation added between elements can add or remove a visible space between inline elements such as links and spans, so check those spots. The contents of pre, textarea, script and style elements are kept exactly as they were.

How do I format HTML in VS Code?

VS Code formats HTML out of the box: open the file and run Format Document (Shift+Alt+F on Windows, Shift+Option+F on macOS, Ctrl+Shift+I on Linux). The Prettier extension is a popular alternative with more options. For a quick one-off format of copied markup, paste it here.

What is the difference between an HTML formatter and an HTML minifier?

A formatter adds line breaks and indentation for readability. A minifier removes them to make the file smaller. Use the HTML Minifier for production output.

Is my data safe?

Processing happens locally in your browser. Tool input is not sent to CodeUnpack servers.

Does it work offline?

Once the page has loaded, this tool can process input without an internet connection.

More formatters & viewers tools

View all