HTML Formatter

Indent and tidy messy HTML so you can read it.

Code Formatters Free, no sign-up Runs in your browser

HTML Formatter tool

About the HTML Formatter

HTML Formatter takes markup that arrived as one long line, or indented by five different people, and prints it with consistent indentation so the structure is visible. Nesting becomes obvious, a missing closing tag becomes obvious, and the whole thing becomes something you can read rather than decode.

Formatting respects the places where whitespace matters. The contents of pre and textarea elements are left exactly as they were, because adding indentation inside them changes what the page displays. Script and style blocks are kept intact rather than being indented as if they were markup. Comments, doctype declarations and self-closing tags are all handled rather than mangled.

Inline elements such as span, a and strong stay on the line with their surrounding text, because breaking them onto their own lines introduces whitespace that changes the rendered spacing. That one rule is the difference between a formatter you can use on real pages and one you cannot.

How to use the HTML Formatter

  1. Paste your HTMLMinified, badly indented or hand-written, it does not matter.
  2. Choose an indentTwo spaces, four spaces or a tab.
  3. Press FormatThe indented version appears below.
  4. Copy or downloadTake the formatted markup in one click.

Features

  • Consistent indentation with two spaces, four spaces or tabs
  • Leaves pre and textarea content untouched
  • Keeps script and style blocks intact
  • Inline elements stay on the line with their text
  • Handles comments, doctype and self-closing tags
  • Optional attribute wrapping for long tags
  • Reports unclosed tags it had to guess about
  • Copy or download the result

Who uses this tool

The html formatter is used by writers, developers, students, marketers and anyone else who needs the job done once without installing software. Common cases include:

  • Reading minified HTML from a built page
  • Tidying markup copied out of a CMS editor
  • Making a diff readable before reviewing it
  • Finding a missing closing tag by eye
  • Normalising indentation across a team

Frequently asked questions

Does formatting change how the page renders?

It should not, and the tool takes care to avoid the cases where it would. Whitespace inside pre and textarea is preserved, and inline elements are not broken onto their own lines, because both of those changes are visible on the rendered page.

What happens to unclosed tags?

The formatter makes a reasonable guess and tells you where it had to. A missing closing tag is a real bug, so having it pointed out is usually more useful than having it silently papered over.

Is script and style content formatted too?

No. Those blocks are kept as they are. Use the CSS and JavaScript formatters for their contents, because formatting them as markup would corrupt them.

Can I format a whole page including the doctype?

Yes. Doctype declarations, conditional comments and processing instructions are all passed through correctly.

Why is my attribute order unchanged?

Because reordering attributes is not formatting, it is editing. The formatter changes whitespace only, so a diff against your original shows indentation changes and nothing else.

Is my markup uploaded?

No. Formatting happens in your browser, so unpublished pages and client work stay on your device.

If the html formatter is not quite what you need, these other free tools solve closely related problems.

HTML Minifier

Shrink HTML by removing comments and collapsing whitespace, safely.

Code Formatters Use tool

CSS Formatter

Format CSS with consistent indentation, spacing and one declaration per line.

Code Formatters Use tool

JavaScript Formatter

Format JavaScript with consistent indentation, spacing and statement breaks.

Code Formatters Use tool

Live HTML Editor

A three-pane editor with a live preview that updates as you type.

Developer Tools Use tool

HTML to Markdown

Convert HTML into Markdown, keeping headings, lists, links and tables.

Code Formatters Use tool