Home/Tools/Developer Tools/HTML Formatter

HTML Formatter

Developer Tools

Format and beautify messy HTML code with proper indentation.

⚡ Instant🔒 Private, in your browser🆓 Free, no sign-up👥 For developers
Your data never leaves your browser. We do not store inputs.

What HTML Formatter does

The HTML Formatter indents and tidies HTML using Prettier. Whitespace-sensitive elements such as <pre> and <textarea> are left alone, and embedded CSS and JavaScript are formatted too. It runs in your browser.

FV
Reviewed by the FreeToolsVerse team · Last updated · How we check our tools

Features and benefits

  • Formats HTML with Prettier, including embedded CSS in style and JavaScript in script elements
  • Leaves pre and textarea contents alone and keeps inline text on one line where splitting would add visible space
  • Choose a 2-space, 4-space or tab indent and a line width of 80, 100 or 120
  • Runs in your browser

How to use HTML Formatter

  1. Paste your HTML
  2. Choose indentation and line width
  3. Click Format
  4. Copy or download the formatted HTML

Who should use it

Made for developers. Typical uses:

  • Beautifying minified HTML for editing
  • Formatting HTML emails for readability
  • Debugging markup structure issues

Example

The one-line snippet <div><p>Hello <strong>world</strong></p></div> becomes three lines: the div, the paragraph indented by two spaces with its inline text kept together, and the closing div. The words Hello and world keep a single space between them.

Limitations and accuracy

Formatting can add or remove whitespace between inline elements in ways that are invisible in most layouts but can matter in inline-block designs. To shrink HTML instead, use the HTML Minifier.

Accuracy: Output is tested against known inputs. For production code, review the result and run your own tests.

Expert Tip

Paste a minified page in here to spot nesting mistakes such as a div that never closes, then run the HTML Validator to catch errors the formatter cannot.

Frequently asked questions

How do I use the HTML Formatter?
Paste your HTML, choose the indent and line width, and click Format. Copy the result or download it as formatted.html.
Does it format CSS and JavaScript inside the page?
Yes. Style and script blocks are formatted too, using the same Prettier settings.
Why are some lines still long?
Inline elements such as strong, em and a are not split onto separate lines when that would add visible space, so a long line of inline text is expected.
Does it fix invalid HTML?
No. It lays out markup but does not correct it, so unclosed tags and invalid nesting are passed through or reported. Use the HTML Validator to find them.
Is my HTML uploaded anywhere?
No. Formatting runs in your browser.

HTML Formatter: the complete guide

What the formatter does

The HTML Formatter indents and lays out HTML so that its structure is easy to read. It uses Prettier and you can choose the indent (2 spaces, 4 spaces or tabs) and the line width (80, 100 or 120). Paste the markup, press Format, and copy or download the result as formatted.html. Embedded CSS in style elements and JavaScript in script elements are formatted too, and the document is processed in your browser.

A worked example

The one-line snippet <div><p>Hello <strong>world</strong></p></div> becomes three lines. The div is on the first line, the paragraph is indented by two spaces inside it with Hello <strong>world</strong> kept on one line, and the closing div is on the last line. The words Hello and world stay on one line with a single space between them, because spaces between inline elements affect how the page is displayed.

Whitespace is treated with care

HTML is sensitive to whitespace in some places, so the formatter is careful. The contents of pre and textarea elements are left alone, so preformatted text and code samples keep their spacing. Inline elements such as strong, em, a and span are not split onto separate lines when that could add visible space. Because of that, you may still see long lines of inline text, which is correct. A formatter that always put each tag on its own line would change what the page looks like.

Why format HTML

Readable markup is easier to debug. Pasting a minified page into the formatter shows nesting mistakes, such as a div that never closes or a list item outside a list, at a glance. It is also a quick way to tidy output exported from a page builder or an email tool, and to bring a pasted snippet in line with the rest of your project before you commit it. Once the structure looks right, run the HTML Validator to catch errors the formatter does not.

Format, then minify

Formatting and minifying are opposite jobs. Edit the formatted version, and publish the minified one made with the HTML Minifier. For stylesheets and scripts, there are the matching CSS Formatter and JavaScript Formatter. To turn HTML into another format, the HTML to Markdown converter is useful for moving content.

Limits

The formatter lays out markup, but it does not correct it. Unclosed tags and invalid nesting are passed through or may cause an error. It can add or remove whitespace between inline elements in ways that are invisible in most layouts but can matter in designs built with inline-block elements, so check the page if you format code that will be published. Everything runs in your browser, and the markup you paste, which may include unpublished pages or email templates, is never uploaded. Pick the same indent and line width as your editor, so that a snippet formatted here matches the rest of your project.

Learning resources

Explore more in Developer Tools, read the guides and articles, or see how we test our tools.

Share This Tool