Report a problem

HTML Formatter & Beautifier

Format HTML online with clean, consistent indentation, or switch to Minify to shrink markup for production. Paste code, load the example or upload an .html file. Free, no sign-up, runs entirely in your browser.

Your code never leaves your browser

Formatting and minification run locally in plain JavaScript. Nothing is uploaded or logged.

Input size0 B · 0 lines
Output size0 B · 0 lines

Content inside <pre>, <script>, <style> and <textarea> is preserved byte-for-byte in both modes.

What this HTML formatter does

This HTML formatter (or HTML beautifier, same thing) takes markup that is cramped onto one line, inconsistently indented, or machine-generated, and rewrites it so the nesting structure is obvious at a glance. Block-level elements each get their own line at the correct depth, void elements like <br> and <img> never get phantom closing tags, and inline runs such as <a>, <span> and <strong> stay together on one line so the rendered page cannot shift. You can pick 2-space, 4-space or tab indentation, and optionally wrap very long tags so each attribute sits on its own line.

Switch to Minify mode and the same engine works as an HTML minifier: it collapses whitespace runs between tags to a single space, strips newlines and indentation, and can remove HTML comments. Conditional comments such as <!--[if IE]> are always kept, because old Internet Explorer versions still parse them. Attribute values are never altered, and the contents of <pre>, <script>, <style> and <textarea> elements pass through byte-for-byte in both modes, so scripts, styles and preformatted text behave exactly as before.

Beautify vs minify at a glance

BeautifyMinify
PurposeReadable source for humansSmallest file for browsers
WhitespaceAdds indentation and line breaksCollapses runs to one space, strips newlines
CommentsKept, placed on their own lineOptionally removed (IE conditional comments always kept)
script / style / pre contentUntouched, byte-exactUntouched, byte-exact
When to useEditing, reviewing, debuggingPublishing to production

How to format HTML online

Paste markup into the input box, click Load example to see a sample, or upload a .html file (it is read locally, never sent anywhere). Choose Beautify or Minify, tweak the options, and the output updates instantly with live byte and line counts. Then copy the result or download it as an .html file. Because the whole tool is one static page of JavaScript, it handles large documents without a server and keeps working even if you go offline after the page loads.

Frequently asked questions

What does an HTML formatter do?

An HTML formatter (also called an HTML beautifier) takes cramped or machine-generated markup and rewrites it with consistent indentation and line breaks, so the document's nesting structure is easy to read. The tags, attributes and content stay the same; only the layout of the source code changes.

What is the difference between beautify and minify?

Beautify adds indentation and line breaks to make HTML readable for humans. Minify does the opposite: it strips comments and collapses whitespace to make the file as small as possible for faster delivery to browsers. Use beautify while developing and minify when publishing.

Will formatting change how my page renders?

No. Browsers collapse runs of whitespace in HTML to a single space, and this tool only ever collapses whitespace to a single space or adds it between block-level tags, which rendering ignores. Inline elements such as links and spans are kept together on one line, and the contents of pre, script, style and textarea elements are preserved byte-for-byte, so layout, scripts and styles behave exactly as before.

Is my code uploaded anywhere?

No. All formatting runs locally in your browser with plain JavaScript. Your code never leaves your device, there is no server round-trip, and you can verify it by disconnecting from the internet after the page loads.

Can it format HTML with inline JavaScript or CSS?

Yes. Content inside script and style tags is detected and left completely untouched in both beautify and minify modes, so your JavaScript and CSS keep their original formatting and behaviour. The same protection applies to pre and textarea content.

Related tools