HTML Minifier
Shrink HTML by removing comments and collapsing whitespace, safely.
Indent and tidy messy HTML so you can read it.
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.
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:
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.
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.
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.
Yes. Doctype declarations, conditional comments and processing instructions are all passed through correctly.
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.
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.
Shrink HTML by removing comments and collapsing whitespace, safely.
Format CSS with consistent indentation, spacing and one declaration per line.
Format JavaScript with consistent indentation, spacing and statement breaks.
A three-pane editor with a live preview that updates as you type.
Convert HTML into Markdown, keeping headings, lists, links and tables.