Code tool
HTML Formatter and Minifier
Paste HTML to format and beautify it with clean indentation, or minify it to make the page lighter.
Runs entirely in your browser. Nothing you paste is uploaded.
Paste some HTML to get started.
How to use the HTML Formatter and Minifier
- Paste your HTML into the left box, or load the sample.
- Choose Format to indent it, or Minify to remove the whitespace and comments a browser ignores.
- Copy the result or download it as a file.
What an HTML formatter can safely change
An HTML formatter, or HTML beautifier, re-indents markup so the structure is easy to follow. An HTML minifier strips the characters a browser does not need. This online tool does both and leaves the page looking the same.
Whitespace in HTML is not always meaningless. A space between two links or two words is visible, and everything inside <pre> and <textarea> is shown exactly as written. This tool only adds or removes whitespace at the edges of block elements such as <div>, <p> and <li>, where browsers ignore it, and collapses runs of spaces elsewhere to a single space.
Minify also removes comments (conditional comments are kept), tidies the spacing between attributes, compresses inline <style> blocks and compacts JSON-LD. Attribute values and inline scripts are left as they are.
If your CSS sets white-space: pre on an element other than pre, keep that part unminified, because a tool cannot see your stylesheet. On most pages minified HTML is 10 to 25 percent smaller before compression.
Common questions
How do I format HTML online?
Paste the HTML and choose Format. The formatter indents nested tags and puts each block on its own line.
Will minifying change how my page looks?
It should not. Spaces that affect layout are kept as a single space, and pre, textarea, script and style contents are preserved.
Does it minify the JavaScript inside script tags?
No. Inline scripts are left untouched so nothing breaks. Use the JavaScript Minifier for script files.
Can it fix invalid HTML?
It formats what you give it and does not add missing closing tags. Unclosed list items, paragraphs and table cells are indented sensibly.
Is my HTML uploaded?
No. Everything happens in your browser.
Guides for the HTML Formatter and Minifier
- How to Format and Minify HTML (Without Breaking the Page)Format HTML so it is readable, or minify it so the page is lighter. Which whitespace matters, what a safe minifier removes, and how to do both.
- 12 Common HTML Mistakes and How to Fix ThemTwelve common HTML mistakes with before-and-after fixes: unclosed tags, missing alt text, wrong nesting, duplicate IDs, a missing viewport tag and more.
- Semantic HTML: What It Is and Which Elements to UseSemantic HTML explained: what header, nav, main, article, section, aside and footer mean, when to use each, and how they help SEO and accessibility.
- How to Run HTML, CSS and JavaScript Online (Free HTML Compiler)Run HTML, CSS and JavaScript online without installing anything. How an HTML compiler works, how to read console errors, and when to use one.