← All tools

HTML Formatter

Beautify or minify HTML markup locally in your browser.

Free tool No account
Input
Output

✓ Tags look balanced · 308 B → 397 B (+29%)

AI uses your own key (several are free); a button opens a short setup.
Ready308 in · 397 outProcessed locally · No upload
Enjoying HTML Formatter?Your review and ideas shape what we build next.

Review HTML Formatter

Please don't include file contents or passwords.

About the HTML Formatter

Turn messy or one-line HTML into clean, indented markup, or minify it to make pages smaller. Empty elements such as <br>, <img> and <input> are handled correctly, the contents of <pre>, <textarea>, <script> and <style> are kept exactly, and the tool points out tags that are never closed.

How to use it

  1. Paste your HTML (a whole page or a fragment) into the Input box.
  2. Choose Beautify with 2, 4 or 8 spaces or a tab, or Minify. When minifying you can also remove comments.
  3. Read the status line: “Tags look balanced”, or the line of a tag that's never closed, plus the size before and after.
  4. Copy or download the result.

Tip: Minify is safe for spacing: one space is kept wherever there was some between words and inline tags, so “Hello <b>world</b>” never becomes “Hello<b>world</b>”.

How the beautifier lays HTML out

Block elements on their own lines
<div>, <section>, <ul>, <li>, <table>, headings and paragraphs start new lines and indent what's inside them.
Inline elements stay in the text
<b>, <a>, <span>, <em>, <code> and similar stay on the line with the words around them, as you'd write them.
Short elements on one line
<title>My page</title> or <p>One sentence.</p> stay on a single line when they're short.
Empty elements
<br>, <img>, <input>, <meta>, <link> and <hr> have no closing tag, so nothing after them is pushed deeper.

Code and preformatted text are kept

Whitespace inside <pre> and <textarea> is part of the content, so it's never changed. Inline <script> and <style> blocks are moved to the right indent as a whole, keeping their own line breaks and inner indentation, and minifying only trims the blank lines around them.

To minify the JavaScript or CSS inside them properly, use the JavaScript Minifier and the CSS Minifier.

Tags that may be left open

HTML lets some closing tags be left out: </li>, </p>, </td>, </tr>, </option> and a few others close themselves when the next one starts. The formatter understands this, so <li>One<li>Two lays out as two list items, and these aren't reported as errors.

Other elements, such as <div>, <span>, <section> and <a>, must be closed. If one isn't, the status line names it and the line it's on.

When to minify HTML

Minifying removes the spaces and line breaks between tags and, if you choose, the comments. On a typical page it saves 5–20% before compression; your server's gzip or Brotli compression saves more on top. It's most useful for HTML emails, which some email apps clip when they're too big, and for snippets stored in databases or JSON.

A tidy HTML page, step by step

1. Start with the doctype
<!DOCTYPE html> on the first line tells browsers to use standards mode.
2. Set the language and character set
<html lang="en"> and <meta charset="utf-8"> help screen readers, translation and search engines.
3. A clear head
<title>, the meta description, the viewport tag and your stylesheet links.
4. Meaningful sections
<header>, <nav>, <main>, <article> and <footer> instead of anonymous <div>s make the structure obvious.
5. One <h1>, then <h2> and <h3> in order
Headings in order are how readers, screen readers and search engines understand the page.

Why indentation helps

Indentation shows which element sits inside which, so a misplaced closing tag or a list item outside its list is visible at a glance. It also makes changes in version control easier to review, because each element sits on its own line.

Tips and tricks

Read copied page source

Paste the source of a page (Ctrl + U in most browsers) to see its structure clearly.

Debug a layout

A div that isn't closed shifts everything after it; the status line finds it.

Clean up exported HTML

HTML exported from editors and email builders is often one long line; beautify it before editing.

Keep conditional comments

Remove comments leaves <!--[if mso]> comments for Outlook in place.

Check email size

Gmail clips messages over about 102 KB; minify the HTML and read the size in the status line.

Use tabs if your team does

Choose Tab in the Indent list to match your editor.

Questions

Will beautifying change how my page looks?

No. Only whitespace between tags changes; the spaces you see between words, and anything inside <pre>, stay the same.

Does it format the JavaScript and CSS inside the page?

It indents <script> and <style> blocks as a whole without changing their code. Use the JavaScript and CSS tools to format or minify that code.

Why doesn't it complain about missing </li> or </p>?

HTML allows those end tags to be left out; browsers close them automatically, so it isn't an error.

Can it remove HTML comments?

Yes. Choose Minify and tick remove comments. Outlook conditional comments are kept.

Does it validate my HTML?

It checks that tags are opened and closed properly. For a full standards check, use the W3C validator.

Can I format JSX or Vue templates?

Simple templates usually format well, but special syntax such as {expressions} isn't understood; a code editor's formatter suits those better.

What's the difference between HTML and XML formatting?

HTML has empty tags and optional end tags that XML doesn't allow. For XML files, use the XML Formatter.

Does formatting HTML change how the page looks?

Normally no. Browsers treat runs of spaces and line breaks between tags as a single space, and the tool keeps text on the same line as inline elements such as <b>, <a> and <span>. Content inside <pre> and <textarea> is left exactly as it is.

Why does the tool say a tag is never closed?

An element such as <div> or <span> was opened but its closing tag is missing or comes in the wrong order. Tags whose end tag is optional in HTML, like <li>, <p> and <td>, are not reported.

Should I minify HTML for my website?

It helps a little; most of the saving comes from gzip or Brotli on the server. Minify when every byte counts, such as for email templates or inline snippets, and keep the readable version as your source.

Is my code uploaded?

No. The tool runs in your browser; what you paste never leaves your device and nothing is stored on a server.

Related tools

Updated