HTML Formatter

Indent and tidy messy HTML so you can read it.

HTML Formatter tool

About the HTML Formatter

Markup copied from a page source, a CMS or an email template often arrives as one long line or indented inconsistently by several people, which hides its structure. This HTML formatter prints it with clean, consistent indentation so nesting is visible and a missing closing tag stands out, while leaving pre, script and style blocks exactly as they were, since changing whitespace there could alter how the page behaves. It is useful for reviewing templates, debugging layouts and learning how a page is built. Formatting happens in your browser, so private markup is never uploaded. To shrink the markup again for production, use the HTML Minifier, and for experimenting with changes, the Live HTML Editor.

Some whitespace in HTML is part of the content, and the formatter treats it that way. Text inside pre and textarea elements is displayed exactly as written, so indenting it would change what visitors see; those blocks are left alone. Script and style sections are passed through intact instead of being reshaped as if they were tags. Comments, the doctype and self-closing tags all come out the way they went in.

Inline tags such as a, span and strong remain on the same line as the text around them. Putting each of them on a new line would add spaces to the rendered page and shift words apart, which is the classic way a careless formatter damages a layout. Keeping inline content together is what lets you format real production pages without worrying about how they will look afterwards.

How to use the HTML Formatter

  1. Paste the markupMinified, unevenly indented or written by hand, the formatter accepts all of it, from a short snippet to a complete page.
  2. Set the indentationChoose two spaces, four spaces or a tab.
  3. Run FormatThe neatly indented version appears underneath.
  4. Copy or save itTake the formatted HTML with one click or download it.

HTML Formatter features

  • Even indentation using two spaces, four spaces or tabs
  • Content of pre and textarea left exactly as it was
  • Script and style blocks kept whole
  • Inline tags kept on the line with their text
  • Comments, doctype and self-closing tags handled correctly
  • Optional wrapping of attributes on long tags
  • Notes on unclosed tags it had to guess about
  • Copy or download the formatted markup

Common uses

  • Studying the compressed HTML of a page you are debugging
  • Cleaning up markup exported from a CMS editor
  • Producing a readable diff before a code review
  • Following the indentation to find where an element was never closed
  • Giving a whole team's templates the same indentation

Formatting HTML in practice: finding a missing closing tag, editing email templates, quick SEO checks, inline-block gaps and template files

By the FreeToolsWorld editorial team · Updated November 2026 · How we write and check our guides

Readable markup makes problems visible: a missing closing tag, a duplicated heading, an enormous block of inline styles injected by a page builder. This guide uses formatting to track down a layout bug on a WordPress page, then covers editing exported email templates, quick checks of important tags, whitespace gaps between inline-block elements, the difference between formatting and validation, and working with template files.

A worked example: a sidebar that drops below the content

A WordPress page suddenly shows its sidebar below the main content instead of beside it. Viewing the page source, copying it and formatting it shows the structure clearly. Following the indentation reveals that a widget in the content area opens a div it never closes, so the sidebar ends up nested inside the content column. Disabling that widget, or fixing its output, restores the layout.

Editing email templates

Newsletter builders often export templates as a single dense line of HTML. Formatting the template makes it possible to find the section you need, change a link or a line of text and check that tables are still balanced. Keep a formatted copy as your editable source, since minified versions are hard to maintain.

Quick checks of important tags

A formatted page makes it easy to confirm the essentials: one title element, a meta description, a canonical link, a single h1 heading and sensible heading levels below it. Searching the formatted source for these takes a minute and often reveals duplicates added by themes and plugins competing with each other.

Gaps between inline-block elements

Browsers render whitespace between inline and inline-block elements as a small gap. Placing buttons, images or navigation items on separate lines can introduce gaps that did not exist when they sat on one line. Layouts built with flexbox or grid are immune, but older layouts relying on inline-block should be checked after formatting.

Formatting is not validation

A formatter tidies indentation; it does not check that markup follows the HTML rules. Duplicate IDs, invalid nesting such as a div inside a paragraph, or missing alt attributes remain until a validator, such as the W3C Markup Validation Service, reports them. Formatting first makes the validator's error list much easier to act on.

Template files

Files mixing HTML with server-side or template code, such as PHP, Blade or Liquid, can confuse a formatter, which sees the template syntax as broken markup. Format the rendered output instead, copied from the browser, to understand the structure, and apply fixes in the template itself. Project-wide code formatters with template support suit the source files better.

Spotting page bloat

Formatting exposes large chunks of inline CSS and JavaScript added by page builders, sliders and tracking tools, which slow down page loading. Seeing hundreds of lines of inline styles in the head is often the first clue that a plugin needs replacing or configuring, especially for visitors on slower mobile connections.

Comparing two versions

When a page changes unexpectedly after an update, formatting the old and new source and comparing them line by line shows exactly what changed, such as a missing script, a removed meta tag or altered tracking code. Comparing minified source is nearly impossible, but formatted source diffs cleanly.

Common mistakes

  • Treating formatted markup as validated markup.
  • Formatting layouts that depend on no whitespace between elements without checking them.
  • Running formatters directly on template files with server-side code.
  • Editing minified email templates instead of a formatted source.

Related tools

To shrink markup again for production, use HTML Minifier. To escape snippets for display, try HTML Encoder & Decoder, and to test changes live, Live HTML Editor.

Indentation choices

Two spaces per level is the most common choice for HTML because markup nests deeply, and four spaces quickly pushes content off the right edge. Tabs let each person choose their display width. Whatever the choice, agreeing on one style for a project keeps diffs clean when several people edit the same files.

Checking structured data

Formatted source makes JSON-LD blocks easy to find. Check that each type of structured data appears once, that it matches what the page actually shows, such as the same product price and the same FAQ questions, and then test the page with Google's Rich Results Test to confirm it is read correctly.

Quick accessibility checks

Readable markup shows accessibility gaps at a glance: inputs without labels, images without alt attributes, buttons containing only an icon and links with text such as click here. Fixing these issues improves the page for screen reader users and usually for search engines too.

Finding third-party scripts

Searching formatted source for script tags with external addresses lists every third-party service a page loads, such as analytics, chat widgets, ad scripts and fonts. Removing services that are no longer used speeds up the page and reduces the amount of visitor data shared with outside companies.

Privacy

Formatting runs in your browser. Your markup is not uploaded or stored.

Frequently asked questions

Can formatting change the way my page looks?

It is designed not to. The two changes that would show on screen, extra whitespace inside pre or textarea and inline tags split onto their own lines, are exactly the ones the formatter avoids.

How are unclosed tags dealt with?

The formatter makes a sensible guess about where the element should end and tells you each place it had to do so. An unclosed tag is a genuine bug, so seeing it flagged is more useful than having it hidden.

Are scripts and styles reformatted as well?

No, their contents are passed through untouched, because treating JavaScript or CSS as markup would corrupt it. To tidy that code, paste it into the CSS Formatter or the JavaScript Formatter.

Can I format a complete document, doctype and all?

Yes. The doctype at the top, old-style conditional comments for Internet Explorer and XML processing instructions are all recognised and kept as they are, so a whole page can be formatted in one go, from the first line to the closing html tag.

Why are my attributes still in the same order?

Reordering attributes would be editing your markup, not formatting it. The tool changes only whitespace, so when you compare the result with the original, indentation is the only difference you will see.

Does my HTML get uploaded anywhere?

No. The formatting runs in your browser, which means unpublished pages, client templates and anything under an agreement stay on your own computer the whole time.