HTML Formatter
Beautify messy or minified HTML with clean indentation, smart line wrapping, and warnings for unclosed or mismatched tags.
How to Use the HTML Formatter
- Paste your HTML into the input box, upload an .html file, or load the sample. It's formatted instantly as you type.
- Choose 2-space, 4-space, or tab indentation and a maximum line width of 80, 100, or 120 characters, or no limit.
- Optionally tick "Remove Comments" to strip HTML comments from the output.
- Review any warnings about unclosed or mismatched tags, then copy the formatted HTML or download it as formatted.html.
HTML Formatter Features
- 2-space, 4-space, or tab indentation with 80, 100, or 120 character line wrapping
- Keeps short inline content on one line and only breaks lines where whitespace already exists
- Preserves <pre> and <textarea> content and re-indents <script> and <style> blocks
- Warns about unclosed, mismatched, and stray tags with line numbers
- Syntax-highlighted output with copy, download, and optional comment removal
Frequently Asked Questions
Will formatting change how my page looks?
Almost never. The formatter only adds or removes whitespace where browsers ignore it, such as between block elements. Inside paragraphs and other inline content it only breaks lines where a space already exists, and <pre> and <textarea> content is kept exactly as written. Tags, text, and entities aren't rewritten, though attribute values are consistently quoted. Missing end tags are added and stray end tags are dropped, matching how browsers read the page, and each case is listed as a warning.
Does it format the CSS and JavaScript inside <style> and <script> tags?
Those blocks are re-indented to match their place in the document, keeping the code's own relative indentation, but the code itself isn't reformatted. JSON inside application/ld+json and application/json script tags is pretty-printed.
What do the warnings mean?
The formatter reports end tags that have no matching opening tag, elements that are never closed, and elements that are closed out of order, with the line number where each problem starts. Elements whose end tags are optional in HTML, such as <p>, <li>, <td>, and <option>, aren't reported. It isn't a full W3C validator, so it doesn't check attribute names or which elements are allowed inside others.
Does Remove Comments delete conditional comments?
No. Conditional comments such as <!--[if mso]> are kept because Outlook and older versions of Internet Explorer act on them, which makes them important in HTML email templates. All other comments are removed.
Is my HTML uploaded to a server?
No. Formatting happens entirely in your browser, so it's safe to paste internal templates or pages that contain private data.