Free Online HTML Formatter / Minifier
Format, beautify, and minify HTML code.
How to use
Paste your HTML into the input box, or open an .html file.
Choose Format to indent it or Minify to shorten it.
Check the output. A message appears if the markup cannot be parsed.
Copy the result or download it as formatted.html or minified.html.
Why use this tool
Indented structure
Nested elements are laid out so that each level is easy to see.
Inline CSS and JavaScript
Code in style and script elements is formatted too.
Minify option
Removes comments and the line breaks between elements.
About this tool
HTML Formatter makes markup readable or compact. Format uses Prettier to indent nested elements so you can follow the structure of a page, and it also tidies the CSS in style elements and the JavaScript in script elements. It treats spaces the way the browser's default styles would, so it avoids adding gaps where they would show. Minify removes HTML comments and line breaks to produce shorter markup. The output updates as you type. The page opens with an example.
Frequently asked questions
No. Unclosed or wrongly nested tags can cause an error or an unexpected layout. Use a validator to find problems.
Format is meant to keep what the browser shows. It can move attributes onto new lines and tidy quotes and code inside script and style elements.
Check the result first. Minify joins lines, including lines inside pre and textarea elements, and a // comment inside an inline script can then swallow the code after it.
No. The output uses two spaces.
Yes. A fragment such as one section or a list works without the html and body tags.