Markup rarely stays tidy. View a page's source and the browser hands you lines of compressed code with no indentation at all. Copy an email template out of a campaign tool, or inherit markup that was generated by something else, and you get the same wall of text: technically complete, practically unreadable. When code cannot be read, it cannot be reviewed, and nesting mistakes hide in plain sight because nothing lines up.
Formatting is the mechanical fix for that problem. This guide shows how to tidy markup with the free HTML Formatter on Ovatly, which turns messy HTML into clean, indented code you can actually read, and can also minify HTML when you want the opposite. It is equally clear about what the tool does not do: formatting fixes indentation only, so it will not rescue markup that is genuinely broken.
Contents
- Quick answer
- What formatting changes, and what it leaves alone
- Format or minify: two different jobs
- How to format HTML, step by step
- Worked example: formatting compact markup
- Limitations and alternatives
- Common mistakes
- FAQs
- Conclusion
Quick answer
Paste your HTML into the HTML Formatter, choose an indent size of 2 or 4 spaces, and press Format HTML. The markup comes back re-indented so the nesting is visible, ready to copy or download as a text file. Press Minify HTML instead and the tool compresses the markup by removing comments and the whitespace between tags. Both operations run entirely in your browser; nothing is uploaded. What neither operation does is repair the markup itself: invalid HTML stays invalid, and missing closing tags stay missing.
What formatting changes, and what it leaves alone
A formatter works on the whitespace of your markup, not on its meaning. It reads the structure of nested elements and rewrites the indentation so a child sits visibly inside its parent, one level deeper per layer of nesting. Tags, attributes, text content and the order of elements all stay exactly as they were. What changes is only how the code is laid out on the page, which is why formatting is safe to apply to markup you did not write: you are changing its readability, not its behaviour.
That narrow scope cuts both ways. Because the formatter assumes the markup is broadly valid, it does not repair invalid HTML, close missing tags or validate your markup. Feed it mismatched tags and the output may still be messy, because there is no clean nesting to reveal. A validator is the right tool for that job; the formatter's job starts once the structure is sound and only the presentation is a mess.
The moments that call for it are predictable: after viewing a page's source and copying a section out of it, after lifting an email template out of a campaign tool, or after inheriting markup that was generated by something else and never meant to be read by a person. In each case the markup may work perfectly and still be unusable for review until its indentation shows where each element starts and ends.
Format or minify: two different jobs
The same tool offers both directions, and they serve opposite moments in a page's life.
Format is for reading and editing. Beautified markup with a consistent 2 or 4 space indent is what you want while developing, reviewing a template, or picking apart markup you copied from somewhere else.
Minify is for shipping. Minifying removes comments and the whitespace between tags, so the markup shrinks to close to a single line. One protection matters here: the content of pre, textarea, script and style blocks is left untouched when minifying, because whitespace inside those elements can be meaningful. A formatted block of preformatted text or a script would break if its internal spacing were collapsed, so the minifier skips those interiors and only compresses the markup around them.
How to format HTML, step by step
- Open the HTML Formatter and paste your HTML into the input box.
- Choose an indent size of 2 or 4 spaces if you plan to format. Match the convention your project already uses.
- Press Format HTML to beautify the markup, or Minify HTML to compress it.
- Copy the result, or download it as a text file.
Worked example: formatting compact markup
Take the kind of one-line markup that page source and generators produce:
<div><p>Hello</p><p>World</p></div>
With a 2-space indent, Format HTML returns:
<div>
<p>Hello</p>
<p>World</p>
</div>
Nothing about the markup changed: the same div wrapping the same two p elements with the same text. What changed is that the structure is now visible at a glance, and it would stay visible in a document a hundred times this size. Minified, the same markup comes back as a single line with inter-tag whitespace removed, which is the form you would ship rather than the form you would edit.
Limitations and alternatives
Formatting fixes indentation only. It does not repair invalid HTML, close missing tags or validate your markup, so a page that renders wrongly because its tags are mismatched needs a validator and a manual fix, not a formatter.
Minifying carries one rendering caveat. Indentation changes do not affect rendering in normal HTML, but minifying removes whitespace between tags, which can very occasionally matter for inline elements separated by a space. If a page relies on exact inline spacing, check it after minifying rather than assuming nothing moved.
Very large documents are fine to paste, but formatting happens on your device, so extremely big files may take a moment. And because the tool works in your browser, closing the tab discards the work; download the result if you need to keep it.
Common mistakes
- Expecting the formatter to fix broken pages. If tags are mismatched, formatting cannot invent the correct structure. Validate first, then format.
- Minifying the copy you are still editing. Minified markup is for production. Keep a formatted copy as the one you work on, and minify a copy at the end.
- Forgetting that comments disappear in minified output. Comments are removed because they add bytes and no visible value in production markup. Notes you need to keep belong in the formatted source, not only in the shipped file.
- Assuming minified pages always render identically. The whitespace between inline elements can occasionally be significant. A quick visual check of pages with tight inline spacing is cheap insurance.
- Mixing indent sizes. Picking 4 spaces for one file and 2 for the next makes a codebase harder to scan. Choose the size the project already uses and stay with it.
FAQs
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.
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 happens to HTML comments when minifying? Comments are removed, since they add bytes and no visible value in production markup.
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 formatted markup matches the rest of your codebase.
Conclusion
Readable markup is not a luxury: it is what makes review, debugging and handover possible. Paste the mess into the HTML Formatter, pick your indent, and work with code you can see into; minify a copy only when the page is ready to ship. If your scheduled jobs are what produce or publish that markup, the companion guide of cron expression examples for common schedules covers the timing side, and the rest of this series lives in the Developer Tools guides archive.