HF

HTML Formatter

Beautify or minify HTML code instantly in your browser — no data leaves your device.

Indent:
Opens your print window: choose "Save as PDF". The file is named "HTML Formatter - MondayTool".
About this tool

Last updated:

Beautify or minify HTML

This free HTML formatter has two modes. Beautify puts each tag on its own line with clear indentation, which makes minified or messy HTML readable. Minify does the opposite and removes comments and extra whitespace to make the file smaller. Processing runs in your browser.

How to use it

  1. Paste your HTML into the HTML Input box. A sample page is loaded to start with.
  2. Choose Beautify or Minify.
  3. In Beautify mode, pick an indent of 2 or 4 spaces.
  4. Click Beautify HTML or Minify HTML.
  5. Check the line counts and click Copy to copy the output.

How it works

Beautify reads the HTML from left to right:

  • Each opening tag goes on a new line and increases the indent by one level.
  • Each closing tag reduces the indent by one level.
  • Void elements such as img, br, meta, link and input, and tags ending in />, do not change the indent.
  • Comments and the DOCTYPE are kept on their own lines.
  • The content of script and style tags is kept, with each line trimmed and indented one level deeper.

Example: <ul><li>Home</li></ul> with a 2-space indent becomes:

<ul>
  <li>
    Home
  </li>
</ul>

Minify removes HTML comments, removes whitespace between tags, collapses runs of spaces, and joins all lines into one.

Limitations

  • Inline tags such as strong and a are also put on separate lines, which can add visible spaces between words.
  • Tags left open, such as a <p> or <li> without a closing tag, push the indent too far to the right.
  • Whitespace inside pre and textarea is not preserved.
  • The formatter does not validate HTML or report errors in your markup.

Frequently asked questions

Is this HTML formatter free?

Yes. There is no sign-up and no limit on how often you use it.

Is my HTML sent anywhere?

No. Formatting and minifying happen in your browser and the output is not saved.

More to explore

Related Developer Tools

Browse all tools from the same category.

Showing 1-2 of 49