HTML Formatter — Clean Indentation for Messy Markup
Re-indent messy single-line HTML markup into readable nested element trees.
17 opening tags.
- The content of <pre>, <textarea>, <script> and <style> is left alone (except the CSS option). White space is removed only where browsers do not show it, such as between block tags; spaces between words and inline elements stay.
- The output only changes layout and indentation, not the content, and is tested to stay equivalent to the original.
When to use the HTML Beautifier & Indentation Prettifier
One block element per line
Block elements such as div, section, ul and table get their own line and indentation, while text with inline elements such as b, a and span stays on one line so paragraphs read naturally.
The page looks the same
Spaces between words and inline elements are rendered by browsers, so they are never added or removed. The output is tested with the html5lib parser: the original and the result build the same tree once rendered white space is normalised.
White-space-sensitive content stays intact
The content of pre and textarea is written exactly as it was, leading spaces included. Script and style content is left alone too, unless you choose to format the CSS inside style with the same CSS formatter.
Attributes stay as written
Extra spaces between attributes are tidied, but attribute values, class lists with double spaces and values holding a > included, are not changed at all.
Frequently asked questions
Are comments kept?
Yes. Comments, IE conditional comments included, are written on their own line.
Why do some elements stay on one line?
Paragraphs, headings and table cells that hold only text and inline elements are written on one line so they read easily. Elements that contain other block elements are opened up into indented lines.
Can it format a fragment rather than a whole document?
Yes. A piece of HTML without html, head or body is formatted as it is.
Are unclosed tags fixed?
No. The structure is not changed; the formatter only arranges indentation so imperfect markup stays readable.
Is my code uploaded?
No. Everything runs in your browser.
Similar tools
- HTML Whitespace & Comment MinifierCompress HTML documents by removing redundant whitespace & HTML comments.
- HTML to Clean GitHub Markdown ConverterConvert headings, links, bold/code tags & lists from HTML into clean Markdown.
- Markdown Live Previewer & HTML GeneratorWrite Markdown and simultaneously render clean semantic HTML & live preview.
- CSS Stylesheet Beautifier & PrettifierExpand compressed CSS rulesets into cleanly indented selector properties.