HTML Formatter Online
Paste minified or messy HTML and get readable, consistently indented code, including the CSS in style blocks and the JavaScript in script blocks. The formatter runs in your browser, so your code never leaves your device.
Format your HTML
Paste HTML or open a local .html file, choose an indent style and select Format HTML. Copy or download the result and put it back in your project.
Formatting uses the open-source js-beautify library (version 1.15), loaded into this page. Text inside <pre> and <textarea> is left exactly as written. Keep your original until you have compared the two versions.
What an HTML formatter changes, and what it leaves alone
Formatting is a source-editing step. It rearranges whitespace so the structure is easy to read; elements, attributes and text stay the same.
HTML copied from a template, a CMS export, an email builder or a production page often arrives as one very long line. When dozens of elements share a line, it is easy to miss a closing tag or edit the wrong attribute. The formatter puts block-level elements such as div, section, ul and table on their own lines and indents their children, so the tree you read matches the tree the browser builds.
Style and script blocks are formatted too, using the CSS and JavaScript beautifiers from the same library, so an inline stylesheet ends up with one declaration per line. Inline elements such as a, b and span stay inside their sentence. Breaking them onto separate lines could add a visible space between words, so the formatter only adds line breaks where whitespace has no effect on the rendered page.
A formatter is not a validator. Neatly indented code can still contain duplicate IDs, an image without alt text or a label that points nowhere. Run the result through the HTML checker when you want those problems listed with line numbers, and keep testing the page itself in a browser.
See nesting
Indentation shows which parent each element belongs to, so a misplaced closing tag stands out.
Embedded CSS and JS
Style and script blocks are formatted with matching CSS and JavaScript rules.
Private by design
The formatter runs inside this page. Your HTML is not uploaded or stored.
A compressed snippet, formatted
The same markup before and after formatting with a two-space indent.
In the compressed version it is hard to tell whether the list belongs inside the main element or follows it. After formatting, the answer is visible at a glance: ul is indented under main, and each li under ul.
The sentence inside the paragraph did not move, and neither did the link in the middle of it. The two adjacent span elements at the end also stay joined, because adding a line break between them would put a space between the letters on the page.
<!-- Input -->
<main><h1>Plan</h1><ul><li>Draft</li><li>Review</li></ul><p>Read the <a href="/guide/">guide</a> first.</p><span>a</span><span>b</span></main>
<!-- Output -->
<main>
<h1>Plan</h1>
<ul>
<li>Draft</li>
<li>Review</li>
</ul>
<p>Read the <a href="/guide/">guide</a> first.</p><span>a</span><span>b</span>
</main>Format a file safely in four steps
Formatting is low-risk, but a quick comparison keeps it that way.
If your repository already formats code automatically, for example with Prettier in a pre-commit hook, keep using that tool so formatting changes do not create noisy diffs.
Formatter, minifier or checker?
All three read the same HTML, but each answers a different question.
Formatter
Makes source readable for editing, code review and debugging. Use it on files people work on.
Minifier
Removes comments and spare whitespace for a smaller delivered file. Use it on output, not on the copy you edit.
Checker
Lists unclosed tags, duplicate IDs, missing alt text and similar mistakes with their line numbers.
HTML formatter questions
Working on a whole project?
The HCODX editor keeps your HTML, CSS and JavaScript files together with a live preview, and has the same formatting command built in.
Instant HTML Runner & Viewer with Live Preview
Need to run a short HTML, CSS and JavaScript snippet? The HTML Runner Online has a focused editing surface with live output.
Open HTML Runner Online