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
- Paste HTML into the box.
- Choose an indent style.
- 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
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.
Related tools
SQL Formatter
Paste your SQL and press Format. Keywords become uppercase, and each clause starts on its own line so...
Developer ToolsCSS Formatter
Paste your CSS, choose an indent style and press Format. You get readable CSS with each declaration on...
Developer ToolsHTML Minifier
Paste your HTML and the minifier removes comments and extra whitespace between tags to reduce file size...
Developer ToolsJSON Formatter and Validator
Paste your JSON and the tool checks that it is valid, then formats it with indentation or compresses it...
Developer ToolsBase64 Encoder and Decoder
Base64 turns text or bytes into a safe string of letters and numbers. Choose encode or decode, paste...
Developer ToolsURL Encoder and Decoder
URL encoding replaces unsafe characters with a percent sign and two hex digits so a link works...
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.