An HTML formatter, or beautifier, rewrites markup with one block element per line and consistent indentation that shows how elements are nested. Paste minified or messy HTML, choose 2 spaces, 4 spaces or tabs, and copy the tidy result. Text and inline tags stay together so the page renders the same.
How to use the HTML Formatter
- Paste your HTMLPaste a whole page or a fragment. Minified one-line HTML is fine.
- Choose the indentPick the indent style and the line width up to which short elements stay on a single line.
- Copy or downloadCopy the formatted HTML or download it as a file.
How the HTML formatter lays out your markup
Good HTML formatting is more than putting every tag on a new line. In HTML, whitespace between inline elements can be visible, so a careless beautifier can add or remove gaps in your text. This HTML formatter treats the two kinds of element differently:
- Block-level elements such as
<div>,<section>,<ul>,<li>,<table>and<p>each start on their own line, indented one level deeper than their parent. - Inline elements such as
<a>,<strong>,<span>,<em>and<img>stay in the flow of the surrounding text, on the same line. - Short elements stay on one line when they fit the width you set, for example
<li><a href="/">Home</a></li>. - Preformatted content inside
<pre>and<textarea>is copied exactly, since every space there is significant. - Scripts and styles keep their own line structure; the block is only shifted to the right indentation level.
Runs of whitespace in ordinary text are collapsed to a single space, which is also what the browser does when it renders the page.
Forgiving by design
Real HTML is rarely perfect. The formatter does not reject invalid markup; it follows the same common-sense rules browsers do. Void elements such as <br>, <img>, <input> and <meta> never increase the indent. A new <li>, <td>, <tr> or <option> closes the previous one if its end tag was left out, and a block element closes an open <p>. A closing tag with no matching opening tag is kept but does not disturb the indentation.
It is a formatter, not a validator: it will not tell you about misspelled tags or missing attributes, and it does not add tags that are absent. Very long paragraphs are not wrapped, because inserting line breaks into text is a matter of taste.
Your HTML is processed in the browser and not uploaded. When the page is ready to ship, shrink it with the HTML minifier, and tidy stylesheets with the CSS formatter.
Frequently asked questions
How do I format HTML code online?
Paste it into the HTML formatter, choose 2 spaces, 4 spaces or tabs, and copy the indented result. It works on full pages, fragments and minified HTML.
Will formatting change how my page looks?
It should not. Inline elements and text are kept on the same line, and whitespace is only collapsed in the way browsers already collapse it. Content in pre and textarea is untouched.
Can it fix broken HTML?
No. It copes with unclosed tags when working out the indentation, but it does not add missing tags or report errors.
Does it format the CSS and JavaScript inside the page?
Script and style blocks are re-indented as a whole but their contents are not rewritten. Use the CSS formatter for stylesheets.
Is my HTML uploaded?
No. The formatter runs in your browser and your markup stays on your device.
Last updated 24 November 2026 by the TheTechFolk team.