# HTML Formatter > Format messy HTML with 2 spaces, 4 spaces or a tab, or minify it. The structure check flags unclosed tags, crossed nesting, duplicate IDs and images without alt text. Free, in your browser, nothing is uploaded. ## What it does - Formats HTML with 2 spaces, 4 spaces or a tab, or minifies it for production. - Checks the structure: crossed nesting, unclosed tags, stray end tags, duplicate IDs, images without alt text, missing lang and title, unclosed quotes, comments and tags. - Shows a tag outline (element tree with line numbers) and byte/line counts before and after. - Opens .html files up to 2 MB. Input is read as text only: it is never rendered, never uploaded, never saved. - Formats live while typing for inputs under 300,000 characters; longer inputs wait for the Format button. - Limits: 2,000,000 characters, 256 levels of nesting. ## What formatting changes - Whitespace, line breaks and indentation only. - The content of script, style, pre and textarea is copied character for character. - End tags HTML lets you leave out (li, p, dt, dd, tr, td, th, option and similar) are written out, so the output shows the structure a browser builds. - Minify removes whitespace between block tags and comments (unless keep comments is ticked), and collapses repeated spaces in text. Conditional comments are kept. ## Errors it catches - Crossed nesting: `` closes `
` while ``, `

` are still open. - Unclosed element: `

x

` never closes `
`. - Stray end tag: `

x

` matches nothing open. - Duplicate id, `` without alt, `` without lang, unclosed quote, comment or tag. - Unclosed quotes, tags and comments are hard errors: the run stops and reports the line and column. ## Code snippets Format HTML with Prettier from the command line: ```bash npx prettier --write index.html npx prettier --check "**/*.html" ``` ## Sources - WHATWG HTML Standard, The syntax of HTML: https://html.spec.whatwg.org/multipage/syntax.html - WHATWG HTML Standard, Parsing HTML documents: https://html.spec.whatwg.org/multipage/parsing.html - MDN Web Docs, HTML elements reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements - Prettier, Options: HTML whitespace sensitivity: https://prettier.io/docs/options#html-whitespace-sensitivity - W3C Markup Validation Service: https://validator.w3.org/