HTML Beautifier & Minifier

Format messy HTML with proper indentation or minify it for production. Handles inline styles, scripts, and nested tags.

0 input chars
0 output chars
0% size change
0 lines
Input HTML
Output
Formatted HTML will appear here...
Ad Space

Free Online HTML Beautifier & Minifier

This tool formats messy or minified HTML code with proper indentation and line breaks, making it easy to read and edit. It also includes a minification mode that removes all unnecessary whitespace, comments, and line breaks to produce the smallest possible HTML for production use. Everything runs in your browser — no data is sent to any server.

Beautify Mode

The beautifier parses your HTML and adds proper indentation based on tag nesting level. It handles self-closing tags, inline elements, void elements (like img, br, input), script and style blocks, and HTML comments. Choose between 2-space, 4-space, or tab indentation to match your coding style.

Minify Mode

The minifier removes unnecessary whitespace between tags, collapses multiple spaces into one, removes HTML comments, and strips blank lines. This reduces file size for faster page loading. Whitespace inside pre and code tags is preserved to maintain formatting of code blocks.

Frequently Asked Questions

Does it preserve inline JavaScript and CSS?

Yes. Content inside script and style tags is preserved as-is during beautification. The tool focuses on HTML structure formatting and doesn't modify embedded code.

How much file size reduction can I expect from minification?

Typical HTML files see a 10-30% size reduction from minification, depending on how much whitespace and comments the original contains. Files with heavy indentation see the largest savings.

Does it fix broken HTML?

This tool formats existing HTML but doesn't repair broken markup. Missing closing tags, malformed attributes, or invalid nesting won't be corrected — use an HTML validator for that.

'; beautify(); } function clearAll(){document.getElementById('inputText').value='';reset()} async function pasteHTML(){try{document.getElementById('inputText').value=await navigator.clipboard.readText();beautify()}catch{}} function copyOutput(){const t=document.getElementById('outputText').textContent;if(!t||t.startsWith('Formatted'))return;navigator.clipboard.writeText(t).then(()=>{const b=document.getElementById('copyBtn');b.textContent='Copied!';setTimeout(()=>b.textContent='Copy',1500)})} function downloadOutput(){const t=document.getElementById('outputText').textContent;if(!t||t.startsWith('Formatted'))return;const b=new Blob([t],{type:'text/html'});const u=URL.createObjectURL(b);const a=document.createElement('a');a.href=u;a.download='formatted.html';a.click();URL.revokeObjectURL(u)}