# HTML Formatter, Beautifier & Minifier Online - Handles pre, script and style, with Live Preview

> Free online HTML formatter: beautify or minify in one click, keep <pre> and <textarea> intact, format embedded CSS and JSON-LD, with a sandboxed live preview.

- URL: https://qilingtools.com/en/html-format
- Category: Developer Tools (https://qilingtools.com/en/dev)
- Tags: [Developer](https://qilingtools.com/en/tags/dev), [Code Formatting](https://qilingtools.com/en/tags/format), [Frontend](https://qilingtools.com/en/tags/frontend)
- Last updated: 2026-10-26
- Price: Free, no sign-up
- Privacy: Runs locally in the browser; files are never uploaded

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.

## How to use

1. Paste HTML or a whole page source (or click Sample to try it)
2. Choose Beautify or Minify and set indent, attribute wrapping, line width and comment handling
3. Check the live preview, then copy the result or download an .html file

## Features

- Block indentation without breaking inline elements, so rendering is unchanged
- <pre> and <textarea> kept verbatim; <script> only re-indented
- Embedded CSS and JSON-LD beautified or minified
- Attribute wrapping (too long / more than N attributes) and adjustable line width
- Closes unclosed tags; keeps conditional comments and DOCTYPE
- Sandboxed iframe live preview
- Runs locally, code never uploaded

## 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.

## Related tools

- [JSON Formatter](https://qilingtools.com/en/json): Free online JSON formatter: beautify or minify, validate with the exact line and column of any error, browse a collapsible tree, sort keys and escape strings.
- [Base64 Encode/Decode](https://qilingtools.com/en/base64): Free online Base64 encoder and decoder: UTF-8 safe, optional URL-safe variant, convert text to Base64 and back in real time. Processed locally, never uploaded.
- [URL Encode/Decode](https://qilingtools.com/en/url-encode): Free online URL encoder and decoder with encodeURIComponent and encodeURI modes. Escapes Chinese, spaces and special characters. Real-time and local, no upload.
- [JWT Decoder](https://qilingtools.com/en/jwt): Free online JWT decoder: decode the header and payload of a JSON Web Token, show expiry and issued-at times, all locally without uploading the token.
- [Timestamp Converter](https://qilingtools.com/en/timestamp): Free online Unix timestamp converter: convert timestamps and dates, auto-detect seconds or milliseconds, and show local, UTC, ISO 8601 and relative time.
- [Hash / Checksum](https://qilingtools.com/en/hash): Free online hash calculator: SHA-1, SHA-256, SHA-384 and SHA-512 of text or any file through the browser crypto API. Files never leave your device.
- [UUID Generator](https://qilingtools.com/en/uuid): Free online UUID generator: create RFC 4122 UUID v4 in bulk with a cryptographic RNG. Options for uppercase, no hyphens and braces, with one-click copy.
- [Base Converter](https://qilingtools.com/en/base-convert): Free online number base converter: convert between binary, octal, decimal, hexadecimal and any base 2–36. Uses BigInt for huge integers, computed locally.
