HTML formatter
Everything runs in your browser; nothing is sent or stored.
- Paste a full page or a code snippet into the "HTML code" field, and click "Format" or "Minify". The code is read as text only: it is not shown on the page, scripts do not run, and images and links are not loaded.
- Under "Indent", choose "2 spaces", "4 spaces", or "Tab", and the code is formatted again with your choice.
- The content of pre, textarea, script, and style does not change, and tags and attributes stay exactly as written. When formatting, block elements (such as div, p, and li) get their own line, and text and inline elements (such as a, b, and span) stay together.
- Under "Minify", select or clear "Remove comments when minifying". Changing the option minifies the code again.
- Minifying removes whitespace next to block tags, and inside text each run of whitespace becomes one character. If your site's CSS sets white-space: pre on an element other than pre, or display: inline-block on a block element, the spacing on the page may change.
- Below the result, the tool shows the size in bytes before and after processing, and when you minify, the percentage saved. Copy the result by clicking "Copy".
Formatting HTML code by page structure
HTML code generated by content management systems, visual editors, or templates often comes in long lines without indentation. When you format the code, each nesting level is indented, and the tags in the head section, such as meta, link, and title, also get their own line. A block element that holds a single line of content, such as an li with a link, is written on one line together with its closing tag, which keeps the code short. Elements whose closing tag the HTML standard allows you to omit, such as li and p, are indented at the correct level even when the closing tag is missing.
What changes when you minify HTML
Minification removes the spaces and line breaks next to block tags, and shortens every run of whitespace inside text to a single character. A space between two inline elements, such as two links, is not removed, because the browser displays it as a space between words. On pages with deep indentation and many comments, whitespace and comments make up a large part of the code size, so minification makes the page significantly smaller.
Comments in HTML code
HTML comments are sent to every visitor and appear in the page source, even though they are not displayed on the page itself. So never put internal information in comments, such as passwords, addresses of development environments, or details about how the system is built. When you format the code, comments are always kept, and when you minify it, they are removed only when the "Remove comments when minifying" option is selected.
HTML snippets and their minified result
<p>Hello <b>world</b></p>the run of spaces becomes a single space, and the result is<p>Hello <b>world</b></p>.<div> <span>a</span> </div>the spaces next to the div tags are removed, and the result is<div><span>a</span></div>.<span>a</span> <span>b</span>the space between the two elements is kept, because it is displayed on the page.<!-- menu -->the comment is removed when the "Remove comments when minifying" option is selected.
A site built with HTML, CSS, and JavaScript can be hosted on static website hosting plans.
HTML formatter FAQ
Does the tool fix errors in HTML code?
No. The HTML formatter does not add missing closing tags or fix errors, but the indentation makes errors easier to find. When a closing tag is missing, the opening tag appears in the result without a closing tag below it at the same indent level.
Does minification also shrink the CSS and JavaScript inside the page?
No. The content of the style and script tags stays the same, both when you format the code and when you minify it. To format or minify CSS, you can paste the content of the style tag into the "CSS formatter" tool.
Why are there still line breaks in the minified result?
Inside text, a run of whitespace that includes a line break becomes a single line break rather than a space, and the browser displays it as a regular space. The content of the pre, textarea, script, and style tags also keeps its original line breaks.
Does minification change the tag attributes?
No. Tags and attributes stay exactly as written, including the quotes and the spaces inside the tag. Minification changes only the whitespace between tags and inside text, and removes comments when the option is selected.
What is the maximum size of HTML code I can format?
The input can be up to 1 MB, and the result can be up to 4 MB.