Skip to content
toolgrid

No tool found. Try another word.

HTML Formatter

Beautify messy or minified HTML: consistent indentation, one block element per line, and formatted inline CSS and JavaScript. Choose 2 or 4 spaces or tabs.

Runs in your browser. What you enter is kept for 30 days to improve Toolgrid, then deleted.

How to use the HTML Formatter

  1. 1 Paste your HTML.
  2. 2 Choose the indentation and, if you like, a maximum line length.
  3. 3 Copy the formatted HTML or download it.

About the HTML Formatter

Minified templates, HTML copied from a browser's developer tools or generated by a CMS is often one long line or badly indented. The formatter rewrites it with one block element per line and consistent indentation, so the structure of the document becomes visible again.

Inline elements such as <a>, <strong> and <em> stay inside their line of text, so formatting doesn't add unwanted spaces to your content. The contents of <style> and <script> are formatted as CSS and JavaScript; <pre> and <textarea> are left as they are, because whitespace matters there.

The formatter uses js-beautify, the same engine behind many editor plugins. It only changes whitespace between tags; attributes, text and comments stay the same. It doesn't validate your HTML, so unclosed tags are formatted as they are; use the browser's developer tools or the W3C validator to find structural errors.

Frequently asked questions

Does formatting change how my page looks?

Normally not, because browsers collapse whitespace between block elements. Between inline elements a line break counts as a space, which the formatter avoids by keeping inline elements together.

Can it fix broken HTML?

No. It indents what is there; missing closing tags stay missing. The indentation often makes such mistakes easier to spot.

Is my code uploaded?

Formatting runs in your browser. As our privacy page explains, input is logged for 30 days to improve Toolgrid, so don't paste confidential code.

Tabs or spaces?

Use what your project uses. Two spaces is common in HTML templates; four spaces or tabs are popular too. Line wrapping is off by default so long lines of text stay intact.