Open the HTML view of a page you built in a content management system and you rarely get the tidy code you imagined. Lines start wherever the editor left them. A heading sits twelve spaces deep, the paragraph under it sits at column zero, and a list is indented as if it belonged to three different documents at once. Markup copied out of a word processor is worse: whole blocks arrive on a handful of very long lines, mixed with short fragments, and nothing lines up with anything.

The page usually renders fine. That is not the problem. The problem is that unreadable markup cannot be reviewed, edited safely or handed to anyone else. When you cannot see which elements sit inside which, every change becomes guesswork, and a stray closing tag can hide for months. This guide shows how to restore the structure with one formatting pass through the free HTML Formatter on Ovatly, and it is plain about the boundary: the formatter fixes indentation, nothing more.

Contents

  • Quick answer
  • Why pasted markup arrives in such a mess
  • What one formatting pass actually changes
  • How to clean up pasted HTML, step by step
  • Worked example: a blog block copied from a CMS
  • Limitations and honest expectations
  • Common mistakes
  • FAQs
  • Conclusion

Quick answer

Copy the HTML out of your CMS or document, paste it into the HTML Formatter, choose an indent size of 2 or 4 spaces, and press Format HTML. The markup comes back re-indented so each element sits at the depth of its parent, ready to copy back or download as a text file. Tags, attributes, text and inline styles are all left exactly as they were; only the layout of the code changes. Formatting will not repair invalid HTML, close missing tags or remove anything your editor added.

Why pasted markup arrives in such a mess

Editors do not store your page the way you would write it by hand. A visual editor thinks in blocks and selections, not in lines of code, so when it serialises a page it writes the markup out in whatever order and spacing its internal model produces. Indentation, if it survives at all, reflects the editor's bookkeeping rather than the document's structure.

Word processors add a second problem. Text copied from a document carries the document's own habits with it: long runs of content on single lines, spacing created by empty paragraphs, and inline styles attached to spans throughout the text. Paste that into a web page or an email template and the result is technically HTML, but laid out in a way no human would choose.

The tool's own description names the same situations: markup copied from page source or an email template, or inherited from something that generated it. Pasted CMS output is that third case: generated, not written, and generated markup is written for machines to parse, not for people to read.

What one formatting pass actually changes

A formatter works on the whitespace of your markup, not on its meaning. It reads the nesting of the elements and rewrites each line's indentation so a child sits one level deeper than its parent, consistently, all the way down the document. One level is your chosen indent: 2 or 4 spaces.

Everything else stays put. The order of elements does not change. Attributes keep their values. Text content is untouched. Inline styles that a CMS attached to an element remain attached, because removing them would be editing, not formatting. This narrow scope is what makes the pass safe to run on markup you did not write and do not fully understand yet: you get the same document back, drawn so its structure can finally be seen.

That visibility is the real product. Once the indentation is honest, you can see where a container opens and closes, spot an element pasted in twice, and find the exact line to edit. Most cleanup work, deleting a stray wrapper, removing an empty block, changing a heading level, becomes straightforward only after this pass, because it depends on seeing the structure first.

How to clean up pasted HTML, step by step

  1. Copy the HTML from your CMS's HTML or source view, or from the document you pasted it into, and keep an untouched copy somewhere safe in case you want the original back.
  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 markup is going into.
  4. Press Format HTML.
  5. Read through the result once, top to bottom. This is the moment the structure is visible, so use it to spot duplicated blocks or elements that landed in the wrong parent before you go further.
  6. Copy the formatted result, or download it as a text file, and paste it back where the markup belongs.

Worked example: a blog block copied from a CMS

Here is the kind of fragment that comes out of a visual editor's HTML view, complete with an inline style the editor added and indentation that follows no pattern at all:

<div class="post">
        <h2>Weekly update</h2>
            <p style="margin-bottom: 12px;">Shipments leave on Friday.</p>
     <ul>
            <li>Orders</li>
        <li>Returns</li>
            </ul>
</div>

After one pass through the HTML Formatter with a 2-space indent, the same fragment reads:

<div class="post">
  <h2>Weekly update</h2>
  <p style="margin-bottom: 12px;">Shipments leave on Friday.</p>
  <ul>
    <li>Orders</li>
    <li>Returns</li>
  </ul>
</div>

Compare the two carefully, because what did not change matters as much as what did. The div still carries its class. The p element still carries its inline style, word for word. The list items hold the same text in the same order. The only difference is that every line now sits at the depth of its parent, so the fragment can be read in one pass and edited without guessing. If you want that inline style gone, you now delete it by hand, from markup you can actually see.

Limitations and honest expectations

Formatting fixes indentation only. It does not repair invalid HTML, close missing tags or validate your markup. If the paste brought across mismatched tags, the formatted output may still be messy, because there is no clean nesting to reveal; a validator is the right tool for that problem, and it comes before formatting, not after.

It also removes nothing. Extra wrapper elements, empty paragraphs used for spacing, and inline styles all survive the pass, because the formatter has no way to know which of them you consider junk. Deciding that is your judgement call, made easier by readable code but not automated by it.

Two smaller notes from the tool itself. Very large documents are fine to paste, but formatting happens on your device, so extremely big files may take a moment. And the tool also offers Minify HTML, which does the opposite job, removing comments and the whitespace between tags; that is for finished markup you are about to ship, not for a cleanup you still need to read. When minifying, the content of pre, textarea, script and style blocks is left untouched, because whitespace inside those elements can be meaningful.

Common mistakes

  • Expecting formatting to remove CMS junk. Inline styles, extra spans and empty paragraphs all survive. Formatting makes them visible; removing them is a separate edit.
  • Formatting markup that is actually broken. Mismatched tags in, messy output out. Validate first if the page renders strangely, then format.
  • Pasting the formatted result back into the visual editor. Many visual editors rewrite markup on save. Work in the HTML or source view when you paste cleaned code back, or the editor may undo your tidy indentation.
  • Overwriting the original paste. Keep the raw copy until the cleaned version is in place and checked. Formatting is safe, but the paste-back step is where accidents happen.
  • Minifying the copy you still need to edit. A cleanup ends with readable code. Minify a separate copy later, when the page is ready to ship.

FAQs

Will formatting strip the inline styles my CMS added? No. Formatting fixes indentation only; it does not strip inline styles, remove elements or change attributes. Cleaning those out is a separate, manual editing job once the structure is readable.

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.

Does formatting change how my page renders? Indentation changes do not affect rendering in normal HTML. Minifying removes whitespace between tags, which can very occasionally matter for inline elements separated by a space, so check pages that rely on exact inline spacing.

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

What indent sizes can I choose? 2 or 4 spaces. Pick the one your project already uses, so the cleaned markup matches the rest of your codebase.

Conclusion

Pasted markup is rarely broken, just unreadable, and unreadable is fixable in one pass. Run it through the HTML Formatter, and the structure your CMS hid from you is visible again, ready for whatever editing the page actually needs. Once the markup is clean, its stylesheet often deserves the same treatment in reverse: our sibling guide on how much smaller CSS minification actually makes a file measures that with real numbers, and the rest of the series lives in the Developer Tools guides archive.