tigtools

HTML Formatter

Paste HTML to indent it by nesting level or to strip unneeded whitespace. The code is only processed as text and never rendered.

Runs in your browser No sign-up

Mode
Indentation (spaces)

Enter some input to see the result.

How to use it

  1. Paste HTML into the input box, open an .html file, or try the example.
  2. Choose Beautify for indented, readable markup or Minify for compact output.
  3. When beautifying, choose 2 spaces, 4 spaces or tabs, and decide whether comments are kept.
  4. Copy the result or download it as an .html file.

How it works

The formatter reads the HTML with a lenient tokenizer, much like a browser does, and writes it out again. It never renders the input, so scripts in the pasted code cannot run and nothing is loaded from the web.

Beautify puts each block-level element (div, p, ul, li, section, table, …) on its own line, indented by its nesting depth. Text and inline elements such as a, b, em, span, code, img and br stay together on one line, so the spaces between words and links are not changed in a way that alters the rendered page. Runs of spaces and line breaks in text become a single space, which is how browsers display them anyway.

The content of pre, textarea, script and style elements is copied exactly as written, including its whitespace and any < or > characters. Void elements such as br, img, input, meta and link never get a closing tag. Self-closing tags like <path /> in inline SVG are kept self-closing.

Minify collapses whitespace in text to single spaces, removes whitespace next to block elements, normalises the spaces between attributes and, if “Keep comments” is off, removes comments. Conditional comments are always kept.

The tool does not fix invalid HTML, add missing tags, reorder attributes or minify the CSS and JavaScript inside style and script elements. Elements that are left open are closed at the end of their parent, and a closing tag with no matching opening tag is kept as written.

Examples

Reading generated markup

A CMS outputs a template as one long line. Beautify with 2 spaces shows the nav, list items and main content as an indented tree, while “Prices include <strong>VAT</strong>.” stays on one readable line.

Preparing an email template

Minify an HTML email with comments turned off to reduce its size. A <pre> block with a price table and the inline <style> are left exactly as they were.

Checking structure

When a closing </div> is missing, the beautified output shows the following elements indented one level too deep, which makes it easy to see where the element should have ended.

Frequently asked questions

Will beautifying change how my page looks?

In almost all cases no. Whitespace inside block elements is collapsed and moved to line breaks, which browsers ignore. Text and inline elements stay on the same line, and pre, textarea, script and style are not touched. Pages that rely on CSS white-space: pre on ordinary elements are the exception.

Does it minify the CSS and JavaScript inside the page?

No. Script and style content is kept exactly as written so it cannot break. Use the CSS formatter to minify a stylesheet separately.

Is it safe to paste HTML from an unknown source?

Yes. The input is treated purely as text and is never inserted into the page, so its scripts do not run and its images or links are not loaded.

Does it validate my HTML?

No. It is lenient on purpose and formats broken markup instead of rejecting it. Mismatched closing tags are kept, so the indentation helps you spot them, but no error list is produced.

Privacy

Your HTML is processed only in your browser and is never rendered or uploaded. Nothing is stored or included in analytics.