HTML Formatterhtmlformatteronline.com

HTML formatter that runs in your browser

Paste messy, minified or exported HTML and get back clean, indented, readable code. Nothing is uploaded — the parsing happens on your own device.

Free no account Private nothing leaves your browser Beautify 2 spaces, 4 spaces or tabs Minify for production Validate with line numbers
Your HTML 0 lines
Format
Formatted 0 lines
Paste HTML on the left, then press the button.

What the formatter actually does

It reads your HTML into a tree, then prints that tree back out with one element per line and a fresh indent at every nesting level. Because it works on the parsed structure rather than on the raw text, it can tell the difference between a tag and a > inside an attribute value — which is where most search-and-replace tidying attempts fall over.

Before
<!DOCTYPE html><html><head><title>Notes</title></head><body><div class="wrap"><h1>Reading list</h1><ul><li>Typography<li>Grid systems</ul><p>Updated <time datetime="2026-04-02">April</time>.</p></div></body></html>
After
<!DOCTYPE html>
<html>
  <head>
    <title>Notes</title>
  </head>
  <body>
    <div class="wrap">
      <h1>Reading list</h1>
      <ul>
        <li>Typography</li>
        <li>Grid systems</li>
      </ul>
      <p>Updated <time datetime="2026-04-02">April</time>.</p>
    </div>
  </body>
</html>

Short elements that only hold text stay on one line, so you do not end up with a thousand-line file where every <li> takes three rows. Anything long enough to need it gets broken out and indented.

Formatters

Same two-panel layout, a different parser behind each one. HTML, JSON, CSS and XML all have their own rules about what counts as structure, and a tool that guesses gets them wrong.

Minifiers and checkers

Strip a file down for production, or find out why it will not parse. Every problem is reported with the line number it came from.

Converters

Move code and text between formats — HTML into React, plain text into Base64, a value into something safe to put in a URL.

Three steps, about ten seconds

Paste or open your HTML

Drop it into the left panel, or use Open file to load an .html file straight off your disk. No sign-in, no upload dialog to a server. If you just want to see what the tool does, press Sample for a deliberately scruffy example.

Choose indent and mode

Two spaces, four spaces or a tab. Decide whether comments survive. Switch between Beautify, Minify and Validate at the top left — the result refreshes immediately when you change an option, so you can compare settings without re-pasting.

Copy, download or keep editing

Copy puts the result on your clipboard. Download saves it as an .html file. Send result back to input moves the output to the left panel so you can run a second pass — handy for beautifying first, reading the code, then minifying the same file.

Keyboard shortcut: Ctrl + Enter (or Cmd + Enter) runs the current mode from inside the input box.

What you get in each mode

</>

Structural indenting

Nesting depth drives the indent, so a missing closing tag shows up as a visible step in the wrong direction rather than hiding in a wall of text.

{ }

Script and style left intact

Contents of <script>, <style>, <pre> and <textarea> are preserved character for character and re-indented as a block.

↵

Sensible line breaking

Inline elements stay inline. A paragraph with a link in the middle of it does not get shredded across five lines the way a naive indenter would do it.

=""

Attribute normalising

Unquoted and single-quoted attribute values are rewritten with double quotes, and tag names are lower-cased, which is the convention every modern style guide agrees on.

↔

Size comparison

Character count in, character count out, and the percentage difference. Useful when you are minifying and want to know whether it was worth it.

!

Problems with line numbers

Validate reports unclosed tags, stray closing tags, duplicate id values and images with no alt, each pinned to the line it came from.

Who ends up here

Developers inheriting someone else's markup

A template from a contractor, a component pulled out of a framework build, a page saved from production — all of it arrives shapeless. Formatting is the first thing you do before you can reason about it.

Email designers

Exports from Mailchimp, Klaviyo and Campaign Monitor are nested tables with inline styles. Indenting them is the difference between finding the cell you want to edit in ten seconds and in ten minutes.

People learning HTML

Running your own work through a formatter shows you your nesting as the browser sees it. If the indent does not match the structure you had in your head, you have found a bug in your mental model.

SEO and content teams

Auditing heading order, structured data or meta tags on a live page means reading its source. Formatted source is readable source.

CMS editors

WYSIWYG editors leave behind empty spans, duplicated wrappers and stray <br> tags. Seeing the markup laid out is how you spot them.

QA and support engineers

Scraped pages, server-rendered output and API responses that return HTML fragments all need to be read before they can be judged.

Questions people ask

Is it really free?

Yes. Every mode — beautify, minify, validate — is free with no account, no usage cap and no paid tier. The site is funded by advertising, which is why you will see ad slots on the page.

Does my code get uploaded anywhere?

No. The parser and printer are JavaScript files that your browser downloads once and then runs locally. Nothing you paste is sent to a server, logged or stored. You can open your browser's network tab and watch: pressing Format makes zero requests. It also means the tool keeps working if you go offline after the page loads.

Will formatting change how my page renders?

Beautify only moves whitespace between tags, so the rendered result is identical — with one exception worth knowing about. Whitespace inside a line of text is meaningful in HTML, so the formatter never touches the contents of <pre> or <textarea>. Minify is more aggressive: it removes comments and collapses runs of whitespace, which can close up the small gap browsers render between inline elements such as <span> or <li> when they sit on separate lines.

How big a file can it handle?

Everything runs on your own CPU, so the ceiling is your device rather than a server quota. Files up to a few hundred kilobytes format in well under a second on a normal laptop. Much beyond a megabyte and a desktop browser will be noticeably happier than a phone.

Can it fix broken HTML?

It can survive broken HTML and tell you where the breakage is, which is usually what you need. The parser recovers from unclosed tags and stray closing tags rather than giving up, and the Validate mode lists each problem with a line number. It does not silently rewrite your markup to make it valid — guessing at intent tends to make the real bug harder to find.

What does it do with script and style blocks?

It leaves their contents alone and re-indents them as a block. JavaScript and CSS have their own formatting rules, and a naive HTML indenter that reformats the inside of a <script> tag will break template literals and regular expressions. So the code inside stays exactly as you wrote it.

Ready when you are

The formatter is at the top of this page — nothing to install, nothing to sign up for.

Back to the formatter

Learn the why, not just the how

Longer reading on formatting, indentation and minification.