🏗️HTML Formatter, Beautifier & Minifier Online - Handles pre, script and style, with Live Preview
Got page source squashed onto one line with messy indentation, or want to shrink HTML before deploying? Paste it in and beautify or minify it in one click. A hand-written, fault-tolerant parser indents block elements level by level while keeping inline elements such as a, span and strong on the same line as their text, wrapping only where whitespace already existed, so the page renders exactly the same after formatting. <pre> and <textarea> content is preserved verbatim, <script> is only re-indented and never rewritten, and CSS inside <style> plus application/ld+json and other JSON scripts are pretty-printed automatically. Choose 2 or 4 spaces or tabs, put each attribute on its own line when a tag is too long or has more than N attributes, and set the line width. Unclosed <p>, <li> and <td> tags are closed for you, while IE conditional comments and the DOCTYPE are kept. Minify mode collapses whitespace, removes whitespace between block elements and ordinary comments, and minifies embedded CSS and JSON while keeping meaningful spaces between inline elements. The live preview renders in a sandboxed iframe with scripts disabled so you can check the result immediately.
Free · No sign-up · Runs in your browserLast updated:
How to use HTML Formatter
- 1Paste HTML or a whole page source (or click Sample to try it)
- 2Choose Beautify or Minify and set indent, attribute wrapping, line width and comment handling
- 3Check the live preview, then copy the result or download an .html file
FAQ
- Will formatting change how my page looks?
- Normally no. Whitespace between block elements does not affect rendering, so it can be re-indented freely. Inline elements (a, span, b, code…) stay on the same line as surrounding text and only wrap where a space already existed, so no spaces are added or removed. Whitespace-sensitive elements such as <pre> and <textarea> are kept exactly as they were.
- What happens to code inside <script> and <style>?
- CSS inside <style> is beautified (or minified) with the site’s CSS formatter, and scripts of type application/json or application/ld+json are parsed and re-printed as JSON. Regular JavaScript is only dedented and re-indented to the right level — it is never rewritten or minified; use a dedicated JS minifier for that.
- How much does HTML minification save, and is it safe?
- Minify collapses runs of whitespace, removes indentation between block elements and ordinary comments (IE conditional comments are kept), and minifies embedded CSS and JSON, typically saving 10–30% on heavily indented pages. Spaces between inline elements and the content of <pre> and <textarea> are preserved, so words never run together. You should still enable gzip or Brotli on your server.
- Is my code uploaded, and does the preview run scripts?
- Nothing is uploaded; formatting and minifying run entirely in your browser. The preview uses an iframe with sandbox="", which blocks scripts, form submission and same-origin access, so JavaScript in the page does not run. External images and stylesheets referenced by the page are still loaded by the browser.