FormatterHQ

HTML Formatter & Beautifier

Indent nested tags, tidy inline <style> and <script> blocks and choose how attributes wrap. Beautify for reading, or minify for production.

Input HTML
Output HTML
Ready.

How to use the HTML Formatter

  1. Paste your HTML into the Input editor, or use Sample, Upload file or Load URL to fetch a page’s source.
  2. Pick an Indent, a Wrap attributes mode, and whether to indent the head and body sections inside the html element.
  3. Press Beautify to format, or Minify to compress the markup. Auto update re-runs the last action while you type.
  4. Use Copy or Download above the output panel to take the HTML with you.

An HTML formatter for real-world markup

This HTML formatter takes markup that is squeezed onto one line, generated by a CMS, or pasted from a page's source and indents it so the element tree is visible. It is powered by js-beautify's HTML beautifier, which also formats the CSS inside <style> and the JavaScript inside <script> elements, so a whole page comes out readable in one pass.

js-beautify is tolerant of imperfect markup. Unclosed paragraphs, missing </li> tags and template placeholders do not stop it; it formats what it finds. That makes it a good fit for HTML you do not control, such as email templates or legacy pages.

Example

<!DOCTYPE html><html><head><title>Demo</title><style>body{font-family:sans-serif;margin:0}</style></head><body><div class="card"><h1>Hello</h1><p>Some <b>bold</b> text and a <a href="#">link</a>.</p><ul><li>One</li><li>Two</li></ul></div></body></html>
<!DOCTYPE html>
<html>

<head>
  <title>Demo</title>
  <style>
    body {
      font-family: sans-serif;
      margin: 0
    }

  </style>
</head>

<body>
  <div class="card">
    <h1>Hello</h1>
    <p>Some <b>bold</b> text and a <a href="#">link</a>.</p>
    <ul>
      <li>One</li>
      <li>Two</li>
    </ul>
  </div>
</body>

</html>

Block elements such as <div>, <ul> and <li> start new lines, while inline elements like <b> and <a> stay inside the paragraph, because breaking them would add visible spaces to the text. By default <head> and <body> are not indented relative to <html>, which saves one level of indentation for the whole document.

Options explained

Indent

2 spaces (default), 3, 4, 8 or tabs. The indent also applies to formatted CSS and JavaScript inside the page.

Wrap attributes

ModeBehavior
AutoAttributes stay on the tag's line. Lines are not wrapped by length.
ForceIf a tag has more than one attribute, every attribute after the first goes on its own line, indented one level.
Force alignedLike Force, but continuation lines are aligned under the first attribute.
PreserveKeeps attribute line breaks exactly as in your input.

With Force aligned, a long form field becomes:

<input type="email"
       id="email"
       name="email"
       required
       placeholder="you@example.com">

Force modes are popular for component-heavy markup (Bootstrap, Tailwind) where elements carry many classes and aria-* attributes, because each attribute change then shows up as a single-line diff.

Indent head and body

When checked, <head> and <body> are indented inside <html>, and everything below them moves one level deeper. Leave it off for full documents to keep lines shorter.

What is preserved

  • Content of <pre> and <textarea> is left exactly as written, since whitespace is significant there.
  • Comments, conditional comments and the doctype are kept.
  • Attribute values and their quotes are not changed.
  • Inline elements are not split in a way that would change rendered spacing.

Beautify or Minify?

Use Beautify while you read, debug or edit markup. Use Minify when you need compact HTML for a template, an email or an embed: it removes comments and collapsible whitespace and shortens boolean attributes. For fine control over what minification does, such as keeping attribute quotes or skipping inline JavaScript, use the dedicated HTML Minifier.

Formatter vs. validator

Because the beautifier is forgiving, it will not tell you that a <div> is never closed; the indentation will simply look wrong from that point on. When the output drifts to the right unexpectedly, run the markup through the HTML Validator, which reports unclosed and mis-nested tags with line numbers. If you want stricter, opinionated output that also closes optional tags and wraps long lines, try HTML Pretty Print, which uses Prettier.

Formatting is done locally in your browser. Load URL fetches a page's HTML so you can inspect it, but the formatting itself never leaves your device.

Frequently asked questions

Does the HTML formatter fix broken HTML?
No. It indents what it receives and does not add missing closing tags. Use the HTML Validator to find unclosed or mis-nested elements, then fix them in the source.
Why are some elements kept on one line?
Inline elements such as a, b, span, label, input and button stay on the same line as their neighbors, because a line break between them would add a visible space in the browser.
Are inline CSS and JavaScript formatted too?
Yes. Code inside style and script elements is formatted with the same indent size, using js-beautify’s CSS and JavaScript beautifiers.
Can I format PHP, Blade or Jinja templates?
Template tags are treated as text, so simple templates usually format fine. Complex logic inside attributes may not be indented perfectly, so review the output before saving.
What does Force aligned do?
It puts each attribute of a multi-attribute tag on its own line and aligns them under the first attribute, which makes long tags easy to scan and diff.

Last updated October 3, 2026

Related tools