What the HTML Formatter does
The HTML Formatter turns minified or messy HTML into neatly indented code, with each block element on its own line and nested elements indented under their parents. CSS inside <style> and JavaScript inside <script> are formatted too. Choose 2 spaces, 4 spaces or tabs and whether long lines wrap. Inline elements such as <b>, <a> and <span> stay within their lines of text so sentences still read naturally.
How to use it
- Paste HTML on the left.
- Choose the indent and line wrapping.
- Read the formatted HTML on the right.
- Copy or download it.
Example
The sample page arrives on one line. Formatted with 2 spaces, <html>, <head>, <body>, <nav> and <main> each get their own lines, the list items are indented under <ul>, Runs in your <b>browser</b>. stays on one line, and the CSS rule for body is spread over several lines inside <style>.
When it helps
Use it to read the source of a page, an email template or HTML exported from a page builder, or to tidy code before committing it. Formatting changes only whitespace, but be careful with elements where spacing matters, such as <pre>, which are kept as they are.
To make HTML smaller for production, use the Code Minifier, which does the opposite.
Questions people ask
Is my code or data uploaded?
No. Everything runs in your browser, so config files, queries, logs and keys stay on your device. That makes it safe to use with work data.
Will it fix broken HTML?
It formats what is there; it does not add missing closing tags. Check the result, as broken nesting will show as odd indentation.
Does it work with templates?
Mostly. Template tags such as {{ }} or {% %} are kept, though complex template logic may indent oddly.
Which library does it use?
js-beautify, a widely used open-source formatter.
Can it format a whole page from my site?
Yes. Open the page, press Ctrl+U to view its source, copy everything and paste it here. Very large pages may take a second or two.