HTML Formatter

Beautify HTML with 2 or 4 space or tab indent. Keeps pre blocks and puts each element and text on its own line. Free, in your browser.

Input
Result

About HTML Formatter

The HTML Formatter re-indents HTML so nested elements are easy to read. Use it on minified pages, snippets copied from a browser and messy templates.

One line per element

Every element and piece of text gets its own line, so the structure is clear. Pre blocks are kept as they are.

Indentation

Two spaces keep deep pages narrow, four spaces are easier on the eyes for short snippets, and a tab lets your editor decide.

Good to know

Splitting inline text onto lines can change the spacing between words on the page, so use the formatted version for reading and keep the original for publishing. No missing closing tags are added, and inline CSS and JavaScript are only indented.

Good for

Front-end developers checking minified output, SEO and content people reading templates, and students learning HTML.

Private

Everything runs in your browser. Your code and data are not uploaded.

Why format HTML?

Readable indentation makes it easy to spot unclosed tags, wrong nesting and duplicated elements, and to review code with others.

How to use HTML Formatter

  1. Paste your HTML or open a file.
  2. Choose the indent size.
  3. Read the formatted code.
  4. Copy it or download it.

Related guide: Speed Up Your Website: Minify CSS, JavaScript and HTML

Help & FAQ

What does the HTML Formatter do?

It re-indents HTML with two spaces, four spaces or tabs so that nested elements are easy to read.

Does it keep pre blocks as they are?

Yes. In the test the pre block kept its spaces and line break.

Why is each word of text on a separate line?

The formatter puts each element and text run on its own line. It looks different from your source but a browser usually shows the same page.

Can formatting change how our page looks?

Rarely. Extra white space between inline elements such as bold text can change spacing slightly, so test before deploying.

Does it close unclosed tags?

No. In the test missing closing tags were left as they were, and no error was shown.

Does it format CSS and JavaScript inside the page?

It indents them but does not beautify them. a{color:red} stayed on one line inside the style tag.

How are void tags like img and br handled?

They are written on their own lines and no closing tag is added.

What indent options are there?

Two spaces, four spaces or a tab.

Is it a validator?

No. It does not check that the HTML is valid or well-formed.

Can we minify the HTML again afterwards?

Yes. Use the HTML Minifier to remove the extra white space.

Can we open a file?

Yes. Use the Open .txt file button or paste the markup.

Is our HTML uploaded?

No. It is formatted in your browser.

More in Developer Tools

See all 39 in Developer Tools