HTML Formatter

Paste HTML that is minified, copied from a page source or edited into a mess, and get it back with every element on its own line and indentation that follows the nesting. The tool reads the markup the way a browser does: text that flows between inline tags such as links and bold stays together, the contents of pre, textarea, script and style are not reflowed, and nothing is added or removed, so the page looks the same afterwards.

What you enter

What you get

How it works

  1. Paste your HTML into the box. A full page or just a fragment both work, and nothing is uploaded.
  2. Choose the indent size: 2 spaces, 4 spaces or a tab. Choose where long text lines should wrap, or turn wrapping off.
  3. Read the formatted markup in the result. Block elements such as div, section, ul and table start on their own lines, and inline elements stay with their text.
  4. Copy the result or download it as an .html file.

How whitespace works in HTML

Browsers treat any run of spaces, tabs and line breaks between words as a single space, so for most elements you can reformat the whitespace freely. The exceptions are the pre element and textarea, where whitespace is part of the content, and the gaps between inline elements, where a collapsed space is still a space.

That is why an HTML formatter has to know which elements are block level and which are inline. Between two blocks, whitespace is ignored and the formatter can put a line break anywhere. Between two inline pieces, the formatter may only break where the original already had whitespace, because a break where there was none adds a space.

Reading messy markup

When a page is minified, a missing closing tag is hard to spot because everything runs together. After formatting, a missing end tag shows up as indentation that never comes back out: the lines after it are all one level deeper than they should be. Scroll to where the indentation stops matching the structure you expect and look at the tag just above.

Pages built by tools often contain deep wrappers, empty containers and inline styles. A formatted view makes those visible, which is the first step in tidying them. When you take over a template or a page exported from a site builder, formatting it first makes the rest of the clean-up quicker.

Tips

Frequently asked questions

What does an HTML formatter do?

It rewrites the whitespace in your markup so the structure is visible: each block element on its own line, children indented one step deeper than their parent and long lines of text wrapped. The elements, attributes and text stay the same.

Why are some tags kept on one line with the text?

In HTML, a space or line break between two inline pieces is rendered as a visible space. In the markup Hello <b>world</b>!, there is no space between the closing b tag and the exclamation mark, so the formatter keeps them together instead of moving the exclamation mark to a new line.

Is the content of script and style tags changed?

The code inside is not reflowed or rewritten. Short ones stay on one line. Longer style blocks, and script blocks without backtick template strings, are re-indented to fit the new nesting depth. Scripts containing backticks are copied exactly, because indenting could change the text of a multi-line template.

What happens with unclosed or mismatched tags?

The tool follows the common browser rules for optional end tags, such as a new li closing the previous li. A closing tag with no matching opening tag is kept on its own line, and a tag that is never closed is printed without a closing tag.

Does it change my attributes or add quotes?

No. It collapses extra whitespace between attributes to a single space, but it keeps attribute order, the quote style and the exact value of every attribute.

Related: HTML table generator, Text to HTML converter, Meta tag generator.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Free Tools

We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.

Product

Who It's For

Features

Resources

Company

View Sitemap