Skip to content

Menu

HTML Formatter

Format, beautify, and minify HTML with configurable indent options.

Runs entirely in your browserFormattersFree, no sign-up
Loading tool

01What is HTML Formatter?

HTML Formatter re-indents HTML for reading, or packs it down for shipping, without changing what the browser draws. That last part is harder than it sounds. HTML whitespace matters in some places and not in others, and a careless formatter quietly breaks pages. Two classic traps. Remove the space in <b>bold</b> <i>italic</i> and the words glue together. Re-indent a <pre> block or a <textarea> and the user sees different text. Under the CSS rules browsers follow, whitespace at the start or end of a line box isn't rendered. So a line break next to a block element is free, and a line break between two inline words is not. This tool follows that split. It reads your markup with its own small tokenizer and only adds or removes breaks next to block-level tags such as div, p, ul, li, table, tr, td, section, head and body. A run of inline content (text, links, spans, bold, images, inputs, line breaks) stays together on one line. Runs of spaces inside it collapse to a single space, which renders the same under normal CSS. Some things are copied byte for byte: everything inside <pre>, <textarea>, <script> and <style>, and every tag itself. Attribute values are never rewritten, and a > inside a quoted attribute doesn't fool the tokenizer. The HTML standard lets you leave out some end tags, like </li>, </td> or </p>. The formatter knows those implied closes, so a list written as <li>One<li>Two indents as two siblings instead of a staircase. It doesn't insert the missing end tags, though. What you wrote is what you get back, just laid out. A worked example: <section><h1>Title</h1><p>Text</p></section> with 4-space Beautify gives section on the first line, h1 and p indented four spaces, and each text eight spaces in. Minify uses the same rules with no indentation. It also drops comments but keeps <!--[if ...]> conditional comments, which old Outlook versions still read in HTML email. Limits, plainly. The formatter doesn't validate HTML or repair broken nesting, so misnested tags pass through as written. It can't see your stylesheet either. If CSS sets white-space: pre on an ordinary div, or display: inline-block on blocks placed side by side, check those spots after formatting. The work happens in your browser tab with plain JavaScript, so templates with private content never leave the page.

Frontend and email developers who need to read or shrink real-world HTML without the formatter changing how it renders. The tool runs entirely in your browser, so your data never leaves your device.

02How to use HTML Formatter

  1. Paste your HTML into the Input HTML box
  2. Pick Beautify or Minify at the top
  3. For Beautify, choose 2, 4 or 8 spaces in the Indent menu
  4. Click Format
  5. Copy the result from the Output box, or use the reset button to start over

03Worked examples

Input: <div><p>Hello <b>world</b></p><ul><li>One<li>Two</ul></div> (Beautify, indent 2)
Result: <div> <p> Hello <b>world</b> </p> <ul> <li> One <li> Two </ul> </div>
Inline tags like <b> stay on the text line, and the unclosed <li> elements are indented as siblings rather than nested, without the formatter adding closing tags.
Input: <pre> keep this</pre><div><br><img src="a.png"></div> (Beautify, indent 2)
Result: <pre> keep this</pre> <div> <br><img src="a.png"> </div>
Whitespace inside <pre> is copied exactly, because changing it would change what the page shows.
Input: <div> <!-- note --> <span>a</span> <span>b</span> </div> (Minify)
Result: <div><span>a</span> <span>b</span></div>
Minify drops the comment but keeps one space between the two spans, since removing it would join "a" and "b" on screen.
Input: <section><h1>Title</h1><p>Text</p></section> (Beautify, indent 4)
Result: <section> <h1> Title </h1> <p> Text </p> </section>
Input: <a title="x > y" href="/a">go</a><div><!--[if mso]><table><![endif]--></div> (Minify)
Result: <a title="x > y" href="/a">go</a><div><!--[if mso]><table><![endif]--></div>
The > inside the quoted title doesn't end the tag, and the Outlook conditional comment survives Minify.
Input: <table><tr><td>1<td>2</table> (Beautify, indent 2)
Result: <table> <tr> <td> 1 <td> 2 </table>
Implied closes for td and tr are understood. No closing tags are added, the output keeps what you wrote.

04Common use cases

  • Beautifying minified HTML from a build tool or CMS to see why a template renders the wrong structure
  • Reading a one-line HTML email template before editing a section of it
  • Cleaning up markup pasted from a WYSIWYG editor before committing it to a repository
  • Minifying a static snippet for an embed field without gluing inline words together or breaking a <pre> code sample
  • Spotting where an implied </li> or </td> ends an element in legacy markup
  • Comparing two versions of a page's HTML after formatting both the same way, so a diff shows real changes

05Tips

  • Whitespace inside <pre>, <textarea>, <script> and <style> is never touched, so code samples keep their indentation
  • Inline elements stay on the same line as the text around them on purpose: splitting them onto separate lines would add visible spaces
  • Minify removes ordinary comments but keeps <!--[if ...]> conditional comments that old Outlook email clients rely on
  • If you style an ordinary element with white-space: pre or pre-wrap, check it after formatting, because the formatter can't see your CSS

06Related concepts

HTML5 spec, Void elements, DOCTYPE, Emmet.

Frequently Asked Questions

What is HTML Formatter?

HTML Formatter is a free, browser-based developer tool on AIDToolStack. Format, beautify, and minify HTML with configurable indent options. It requires no installation or sign-up and works entirely in your browser.

Is HTML Formatter free to use?

Yes. No sign-up, no fees and no usage cap.

Does HTML Formatter store my data?

No. It runs in your browser; nothing is uploaded.

Cheat sheet

Related Tools

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe