Copy HTML out of a browser's page source and you get a single line that runs off the edge of the screen. Lift a template out of an email tool and the indentation is random, three spaces here, a tab there, whole sections collapsed together. Inherit markup from a generator and it may never have been laid out for human eyes at all. The code works, but nobody can read it, which means nobody can safely change it either.

The fix is deliberately small: one formatting pass. This guide walks through cleaning copied markup with the free HTML Formatter on Ovatly, explains exactly what that pass changes, and is plain about what it leaves for other tools.

Contents

  • Quick answer
  • Where messy copied HTML comes from
  • What one formatting pass changes
  • How to fix copied HTML, step by step
  • Worked example: from one line to readable markup
  • What the pass does not fix
  • Common mistakes
  • FAQs
  • Conclusion

Quick answer

Paste the copied HTML into the HTML Formatter, choose an indent size of 2 or 4 spaces, and press Format HTML. The markup comes back re-indented with its nesting visible, ready to copy back into your file or download as a text file. That is the whole job: the pass repairs the layout of the code, not the code itself. Tags, attributes and text are untouched, and invalid markup stays invalid.

Where messy copied HTML comes from

Most copied markup was never meant to be read in the form you receive it. Page source is often served compressed, because the server cares about bytes, not readability. Email templates pass through campaign tools that rewrite and compact the code on the way through. Visual builders and generators emit markup by template, with indentation that reflects the generator's internals rather than any human convention. Hand-me-down files pick up a mix of styles from every editor that ever touched them.

None of that makes the markup wrong. It makes it opaque. You cannot review what you cannot scan, and edits made inside an unreadable block tend to land in the wrong element. A formatting pass is the standard first move because it costs a minute and changes nothing except how the code sits on the page.

What one formatting pass changes

The formatter reads the structure of nested elements and rewrites the whitespace around them. Each child sits one indent deeper than its parent, opening and closing tags line up, and long runs of markup break into lines a person can follow. The indent size is your choice, 2 or 4 spaces, and the sensible pick is whichever your project already uses.

Everything else stays put. The pass does not rename tags, reorder elements, rewrite attributes or touch text content. It also leaves the interiors that matter alone when you later go the other direction: minifying removes comments and the whitespace between tags, but the content of pre, textarea, script and style blocks is left untouched, because whitespace inside those elements can be meaningful. Formatting and minifying are the same tool's two directions, one for reading, one for shipping.

How to fix copied HTML, step by step

  1. Copy the messy markup from wherever it lives: page source, an email template, a generator's output, or an old file.
  2. Open the HTML Formatter and paste the markup into the input box.
  3. Choose an indent size of 2 or 4 spaces, matching the convention of the project the code is going into.
  4. Press Format HTML.
  5. Scan the result. The nesting should now read cleanly, one level per indent step. If a section still looks tangled, that section may have mismatched tags, which formatting cannot repair.
  6. Copy the formatted result back into your file, or download it as a text file if you want to keep it separate.

Worked example: from one line to readable markup

Here is the kind of block that comes out of a navigation template when you copy it from page source:

<ul class="nav"><li><a href="/">Home</a></li><li><a href="/tools">Tools</a><ul><li><a href="/blog">Blog</a></li></ul></li><li><a href="/about">About</a></li></ul>

With a 2-space indent, Format HTML returns:

<ul class="nav">
  <li><a href="/">Home</a></li>
  <li><a href="/tools">Tools</a>
    <ul>
      <li><a href="/blog">Blog</a></li>
    </ul>
  </li>
  <li><a href="/about">About</a></li>
</ul>

Same tags, same links, same text. What changed is that the nested list now visibly belongs to the Tools item, so adding a second sub-item or moving the Blog link becomes a ten-second edit instead of a hunt through a single line. Multiply that clarity across a full template and the pass pays for itself immediately.

What the pass does not fix

Formatting fixes indentation only. It does not repair invalid HTML, close missing tags or validate your markup. If the copied code has mismatched tags, the formatted output may still be messy, because there is no sound structure for the indentation to reveal. Run a validator on genuinely suspect markup, fix the errors it reports, and then format the corrected version.

It also does not modernize anything. Deprecated tags, inline styles and table-based layout from an old email template all survive the pass exactly as written. Cleaning the presentation makes those problems easier to see and fix by hand, which is the honest scope of the tool: readable first, then whatever repairs you choose to make yourself. One more practical note: very large documents are fine to paste, but formatting happens on your device, so an extremely big file may take a moment.

Common mistakes

  • Formatting and then editing the wrong copy. Paste the cleaned version back into the real file. Editing a downloaded copy while the original stays messy splits your work across two versions.
  • Expecting repairs that were never promised. A missing closing tag will still be missing after the pass. Validate broken markup instead of formatting it repeatedly and hoping.
  • Mixing indent sizes across a project. Choosing 4 spaces for one cleaned file and 2 for the next makes the codebase harder to scan. Pick the project's existing size every time.
  • Minifying the copy you still need to edit. Minify HTML is the shipping direction: it removes comments and inter-tag whitespace. Keep the formatted version as your working copy and minify a copy at the end.
  • Skimming the result. A quick scan of the formatted output is where you notice the nested list inside the wrong item or the section that closes early. That scan is most of the value.

FAQs

What does one formatting pass actually fix? Indentation and line breaks. Messy copied markup comes back with one element level per indent step, so the nesting is readable and safe to edit. It does not change any tag, attribute or text.

Will it fix my broken HTML? No. A formatter assumes the markup is broadly valid. If tags are mismatched, the output may still be messy; a validator is the right tool for that.

What indent size should I choose? 2 or 4 spaces, whichever your project already uses. Matching the existing convention keeps the cleaned markup consistent with the rest of your files.

What happens to HTML comments when minifying? Comments are removed, since they add bytes and no visible value in production markup. Formatting, the direction this guide uses, keeps comments in place.

Is my HTML uploaded anywhere? No. Formatting and minifying run entirely in your browser.

Conclusion

Messy copied HTML does not need a rewrite; it needs one honest pass that makes it readable. Paste it into the HTML Formatter, pick your indent, and work with markup you can see into. If the newly readable structure reveals a layout problem hiding in the nesting, the companion guide on why you should format HTML before debugging layout problems shows how to hunt it down, and the rest of this series lives in the Developer Tools guides archive.