Skip to content
CODE FORMATTING & MINIFICATION

HTML Formatter & Beautifier Online

Indent and format HTML so nested tags are easy to read.

  • Free
  • No signup
  • Runs in your browser

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

HTML Formatter

About HTML Formatter

Minified or copied HTML is hard to read because every tag runs together on one line. This formatter splits the markup into tags and text, puts each element on its own line and indents child elements by two spaces so the nesting is visible at a glance.

Elements that contain only text, such as a heading or a list item, stay on one line. Comments and the doctype are kept, and void elements such as img, br and input do not add an indentation level. The tool changes whitespace only; it never adds, removes or reorders tags.

How to use HTML Formatter

  1. Paste your HTML into the input box.
  2. Click Run Tool. The indented markup appears in the output box.
  3. Copy it back into your editor or download it as a text file.

Example

Input

<div class="card"><h2>Free Tools</h2><p>Format <b>HTML</b> online</p><img src="logo.png" alt="Logo"><ul><li>Fast</li><li>Private</li></ul></div>

Output

<div class="card">
  <h2>Free Tools</h2>
  <p>
    Format
    <b>HTML</b>
    online
  </p>
  <img src="logo.png" alt="Logo">
  <ul>
    <li>Fast</li>
    <li>Private</li>
  </ul>
</div>

Common uses

  • Reading the HTML source of a page or an email template that was exported on a single line.
  • Cleaning up markup before you review it in a pull request.
  • Finding an unclosed or misplaced tag by looking at the indentation.

Privacy and safety

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

Frequently asked questions

Does it fix invalid HTML?

No. It only adjusts whitespace. If a tag is missing its closing tag, the indentation will show the problem but the tool will not correct it.

Is whitespace inside pre and textarea preserved?

No. Content is re-flowed, so do not run this on markup where exact spacing inside pre or textarea elements matters. The content of script and style elements is also treated as plain text rather than formatted code.

How is this different from an HTML minifier?

A formatter adds line breaks and indentation for people. A minifier removes whitespace to reduce file size. Use the HTML Minifier for the opposite result.

Learn to build this yourself

Free tutorials and courses on NHP Learning cover PHP, JavaScript, SQL and WordPress, from the basics to real projects.