Free developer tool

HTML Formatter

Paste your HTML and press Format. Each tag is placed on its own line with nested elements indented so the structure is easy to read.

Report a problem or suggest a fix for this tool

What is html formatter?

Pasted or generated HTML often arrives on one line. A formatter breaks it into a clear tree so you can see which tags are nested and spot missing closing tags.

Text inside inline tags stays together, and script, style and pre blocks are kept as written.

How to use the html formatter

  1. Paste HTML into the box.
  2. Choose an indent style.
  3. Press Format HTML and copy the result.

How the html formatter works

The tool splits the markup into tags and text, increases the indent after an opening tag, decreases it at a closing tag and does not indent after void tags such as br, img and meta.

Worked example

A div that holds a heading, a paragraph and a list becomes a tree where the h1, p and ul sit one level inside the div.

Common uses of the html formatter

  • Reading minified HTML.
  • Code review.
  • Cleaning email templates.
  • Teaching HTML structure.
  • Debugging nesting problems.

Tips and common mistakes

Check that every opening tag has a closing tag.

Use the HTML minifier before publishing.

Do not format inside pre blocks.

Background: what to know before you rely on it

HTML is a tree of elements. Seeing the tree makes it easy to find the element you need. Browsers handle both formatted and minified HTML the same way, so use formatted code while you work and minified code when you publish.

Private, free and fast

This tool runs in your browser. What you type or choose is not sent to a server and is not saved after you close the page. No sign in is needed. It is free to use as often as you like. See more in all developer tools, or browse the full list of tools.

Field by field guide

  • HTML code: Type or paste your text here. Use a new line for each entry where the label says so.
  • Indent: Choose one of: 2 spaces; 4 spaces; Tab.

Change one field at a time to see how the result responds, and use the worked example above to check that you get the same answer.

Reading and cleaning HTML

Indentation shows how elements nest, which is the fastest way to spot an unclosed tag or a div in the wrong place.

Practical scenarios

  • Pasting an email template exported on a single line and finding where a table row begins and ends.
  • Reviewing a CMS generated block before you edit it by hand.
  • Teaching nesting rules by showing a flat snippet as an indented tree.

Common mistakes

  • Reformatting whitespace sensitive content such as pre blocks or inline text. Extra line breaks inside inline elements can add visible gaps.
  • Assuming formatting repairs broken markup. Browsers repair HTML their own way, so check the final DOM.
  • Pasting private page data. The tool runs in your browser, but you should still avoid secrets in shared screens.

Keeping HTML readable

Indentation shows structure, and structure is where most layout bugs hide. A neat file is easier to review, test and hand over to a team.

Expert tips

  • Use two spaces per level and keep one block element per line.
  • Close all tags and quote all attributes for consistency.
  • Keep inline elements such as span and a on the same line as their text to avoid stray spaces.
  • Validate the result with the W3C validator when something renders strangely.
  • Do not hand edit minified output. Format it, edit it and minify again.

Formatting does not change how a page looks, apart from rare cases with whitespace sensitive elements.

Frequently asked questions

Does it validate HTML?

No. It only changes layout. It does not fix errors.

Will it break my page?

Whitespace between inline tags may change slightly. Test the result.

Does it format scripts?

Script and style content is left as written.

Is my code uploaded?

No.

Embed this tool on your website

Copy the code below and paste it into your page or blog post. The tool is free to embed, runs in the visitor's browser and needs no account. Please keep the credit link.

Related tools

Results are for information and education. For legal, financial, medical or security decisions, check with a qualified professional. Do not paste live secrets into any website.