Skip to content
FreeRuns in your browser

HTML Formatter

Pretty-print messy or minified HTML with clean indentation, or compress it for production.

Use the HTML Formatter

Loading tool...

What is the HTML Formatter?

HTML delivered by servers, CMS exports and email builders is often a single line or inconsistently indented, which makes debugging layout problems tedious. An HTML formatter parses the markup and writes it back with each nested element on its own line, indented by depth, so the document structure is visible immediately.

Good formatters are careful about whitespace-sensitive content. Text inside <pre> and <textarea> must be left untouched, inline elements such as <a> and <strong> should not gain extra spaces that change how text renders, and the contents of <script> and <style> are treated as code rather than markup.

When to use the HTML Formatter

Format HTML when you inspect markup copied from a browser, clean up the output of a visual editor or email builder, review a template produced by a code generator, or prepare a snippet for documentation. Readable structure makes it far easier to spot a missing closing tag, a wrongly nested list or a div that wraps too much. Minify the final version when you embed HTML in a JavaScript string, an email or a JSON payload where every byte counts.

How to use the HTML Formatter

  1. Paste your HTML into the input area.
  2. Select the indent size: 2 spaces, 4 spaces or tabs.
  3. Press Format to beautify or Minify to compress.
  4. Review the output and look for unclosed or mis-nested tags.
  5. Copy the result back into your editor or template.

Examples

Before:

<div class="card"><h2>Title</h2><p>Hello <strong>world</strong></p><ul><li>One</li><li>Two</li></ul></div>

After:

<div class="card">
  <h2>Title</h2>
  <p>Hello <strong>world</strong></p>
  <ul>
    <li>One</li>
    <li>Two</li>
  </ul>
</div>

Common errors and tips

  • Formatting is not validation. Browsers silently repair broken HTML, so a clean-looking result can still hide a missing closing tag.
  • Void elements such as <br>, <img> and <input> never have closing tags.
  • Minifying removes comments and collapses whitespace; avoid it for content where spacing matters, such as preformatted text.
  • Mis-nested tags like <b><i></b></i> produce odd indentation, which is a useful clue that something is wrong.
  • Run your final markup through the W3C validator for a full standards check.

Privacy: runs entirely in your browser

Markup, including unreleased pages or email templates, is formatted locally in your browser and is never uploaded. This tool runs entirely in your browser: nothing you enter is uploaded, stored or logged on our servers, and it keeps working even if you go offline after the page has loaded.

Frequently asked questions

Does formatting change how my page looks?

It should not. Indentation only adds whitespace between block elements, which browsers collapse. Content in pre and textarea is left unchanged.

What is the difference between beautify and minify?

Beautify adds line breaks and indentation for readability. Minify removes comments and unnecessary whitespace to reduce file size.

Will this fix invalid HTML?

No. It reformats what you give it. Use a validator to find structural errors such as unclosed tags.

Are inline scripts and styles formatted?

Their content is kept intact so behaviour does not change; format it separately with the JavaScript or CSS tools if needed.

Ratings & reviews

–

0 reviews

5 star
0 reviews (0%)
4 star
0 reviews (0%)
3 star
0 reviews (0%)
2 star
0 reviews (0%)
1 star
0 reviews (0%)

No reviews yet — be the first to share your experience.

Write a review

Reviews are moderated before they appear.

Your rating *

Photos or videos (optional)

Drag files here or

JPG, PNG, WebP, GIF up to 5 MB. MP4 or WebM up to 25 MB.

  • Featured

    Beautify, minify and validate JSON instantly, with exact line and column for every syntax error.

    Use tool
  • Featured

    Encode text to Base64 or decode Base64 back to readable UTF-8, including URL-safe Base64.

    Use tool
  • Featured

    Generate random v4 and time-ordered v7 UUIDs in bulk, with one-click copy and format options.

    Use tool
  • Regex Tester

    Developer

    Featured

    Test JavaScript regular expressions live, with highlighted matches, capture groups and flag toggles.

    Use tool
  • JWT Decoder

    Developer

    Featured

    Decode JSON Web Tokens to inspect the header, payload and expiry, all without sending the token anywhere.

    Use tool
  • Featured

    Convert Unix timestamps to readable dates and back, in UTC or your local timezone, in seconds or milliseconds.

    Use tool