How to beautify and reindent HTML
Beautifying HTML puts each tag on its own line and indents it by nesting depth, which turns a minified or machine-generated page into something you can read and navigate. It is what you want when you have pulled markup out of a view-source or an API response.
The formatter runs in your browser. It tracks nesting depth and correctly refuses to indent after a void element such as an image or a line break, which is the detail most simple reindenters get wrong.
- Paste the HTML into the input box.
- Read the indented output, where nesting depth is shown by two spaces per level.
- Check any pre or textarea element, because whitespace inside them is rendered literally and the formatter will have changed it.
- Extract any script or style block and format it with a JavaScript or CSS formatter instead, since its contents are treated as markup here.
- If you are reformatting a file in version control, commit the reformat on its own so the diff does not hide a real change.