How to use the HTML Formatter
Step 1: Paste your HTML into the input box, or press Load example to see how it works.
Step 2: Choose an indentation style: 2 spaces, 4 spaces or a tab.
Step 3: Press Format HTML. The tidy version appears in the output box.
Step 4: Read any warnings about unclosed or unexpected tags.
Step 5: Press Copy output, or Download to save formatted.html.
Features and benefits
Readable structure
Block elements start on their own lines and nested content is indented, so the structure is visible at a glance.
Inline text stays together
Paragraphs with bold text, links and images stay on one line instead of being broken into fragments.
Your indentation
Pick 2 spaces, 4 spaces or tabs. Changing the choice re-formats instantly.
Safe handling
Comments, pre blocks, textareas, scripts and styles are preserved exactly. Nothing is run.
Helpful warnings
Unclosed and stray tags are reported with line numbers.
What the formatter does
The formatter reads your HTML with its own small parser and prints it again with consistent line breaks and indentation. Block-level elements such as div, section, ul and table go on their own lines, and their contents are indented one level deeper. Inline elements such as a, span, strong and em stay inside the flow of their text, so a sentence with a link in it remains one readable line.
Content where whitespace matters is left alone: pre and textarea blocks are copied exactly, and the bodies of script and style tags are re-indented as a block without changing a single character of the code inside them.
Why it is safe to paste untrusted code
The tool never inserts your code into the page, never renders it and never evaluates scripts. The output is shown inside a text box, so even markup containing script tags or event handlers is only text. All processing happens locally in your browser, and nothing is stored.
Limitations to know about
This is a formatter, not a validator. It reports obviously unclosed or stray tags but does not check attributes, nesting rules or accessibility, and it does not repair broken HTML. It also does not reformat the JavaScript or CSS inside script and style tags. Collapsing whitespace between inline elements is normally invisible, but in rare layouts that depend on exact spacing, such as inline-block gaps, compare the page before and after using the formatted code.
Example use cases
Reading minified HTML
Make sense of compressed markup copied from a page or an email template.
Cleaning up generated code
Tidy output from page builders and editors before committing it.
Code reviews and teaching
Present consistently indented examples.
Spotting structural errors
Warnings point to tags that were never closed.
Frequently asked questions
Is it safe to paste HTML containing scripts?
Yes. The code is treated as plain text, is never executed or rendered, and does not leave your browser.
Does the formatter fix broken HTML?
No. It reports unclosed or unexpected tags but keeps your markup as written. Use a validator to fix structural problems.
Will formatting change how my page looks?
Normally not. Whitespace between words is collapsed to single spaces, as browsers do anyway. In unusual layouts that rely on exact whitespace, test the result.
Are comments and conditional comments kept?
Yes. Comments, the doctype and CDATA sections are all preserved.
Is there a size limit?
Up to 1,000,000 characters at a time, which is far more than most pages need.
Related tools
Last updated 7 November 2026.