HTML Formatter
A free tool by DeepRit, a Google Ads agency that does PPC and nothing else. We build and run Google Ads accounts so every click is accounted for. Book a free audit call
Free HTML formatter. Paste messy HTML to beautify it with clean indentation, keeping pre, script and style untouched, or minify it. Nothing is uploaded.
Free, no sign-up. Runs in your browser: nothing you type is uploaded or saved.
How to use the HTML formatter
- Paste your HTML into the box. It can be a whole page or just a fragment.
- Choose a mode: Beautify to add clean line breaks and indentation, or Minify to remove unnecessary whitespace.
- Choose the indentation: 2 spaces, 4 spaces or tabs.
- Copy the result.
The HTML formatter works entirely in your browser. Nothing you paste is uploaded or stored.
What does an HTML formatter do?
HTML often ends up hard to read: copied from a page's source, generated by a content management system, exported from an email builder, or squashed onto a single line to save space. An HTML formatter, also called an HTML beautifier, rewrites the markup with each element on its own line and child elements indented inside their parents, so the structure is easy to see.
For example, this single line:
<div class="card"><h1>Hello</h1><p>Some <b>bold</b> text.</p><ul><li>One</li><li>Two</li></ul></div>
becomes:
<div class="card">
<h1>Hello</h1>
<p>Some <b>bold</b> text.</p>
<ul>
<li>One</li>
<li>Two</li>
</ul>
</div>
Formatting doesn't change what the page shows in a browser in normal cases; it only changes how the source looks to people.
What the HTML formatter keeps unchanged
Some content must not be reformatted, because whitespace inside it matters or it isn't HTML at all. The HTML formatter leaves these exactly as they were:
- pre: preformatted text, where spaces and line breaks are displayed as written.
- textarea: the default text of a form field.
- script: JavaScript, which has its own formatting rules.
- style: CSS stylesheets.
It also keeps inline elements such as b, i, a, span and em on the same line as the text around them. Splitting inline elements onto separate lines can add visible spaces between words, so a careful HTML formatter keeps short blocks of text together.
Beautify or minify?
- Beautify when you need to read, edit, debug or review HTML. Indented code makes it easy to spot unclosed tags, misplaced elements and nesting problems, and it produces cleaner diffs in version control.
- Minify when you want the smallest possible file to send over the network. Minifying removes whitespace between tags and HTML comments, which can make files noticeably smaller, especially for large pages.
Modern web servers usually compress files with gzip or Brotli, which already shrinks repeated whitespace very effectively, so the gain from minifying HTML is often modest. It's still common in build pipelines, and it can matter for very large pages or for HTML embedded in other files.
Void elements
Some HTML elements can't contain content and have no closing tag. These are called void elements, and they include br, hr, img, input, link, meta, source, area, base, col, embed, track and wbr. The HTML formatter knows these elements and doesn't indent anything after them as if they were containers. In HTML, writing them with a trailing slash, such as <br />, is optional; both forms are valid.
Finding structural problems
When the HTML formatter indents your markup, problems often become obvious. If a closing tag is missing, everything after it ends up indented one level too deep. If tags are closed in the wrong order, such as <b><i>text</b></i>, the indentation looks wrong. The formatter warns you when tags don't seem to be closed properly, so you can check the structure. For a full check against the HTML standard, use a validator such as the W3C Markup Validation Service.
A worked example
You've copied a section of a page from a content management system, and it's all on one line:
<section><h2>Pricing</h2><p>Simple plans for <strong>every</strong> team.</p><a href="/signup" class="btn">Start free</a></section>
- Paste it into the HTML formatter and choose Beautify with 2 spaces.
- The section becomes the outer block, with the h2, p and a each on their own lines inside it.
- The strong element stays inside the paragraph's line, because it's inline.
Now it's easy to see that the button link sits directly inside the section, and you can add a wrapper or a class where you need it. Switch to Minify to get the compact version back.
Who uses an HTML formatter
Front-end developers use it to tidy markup before committing it and to read generated HTML. Email developers use it to make sense of exported email templates. Content editors and marketers use it to clean up HTML pasted into content management systems. SEO specialists use it to inspect page structure, headings and meta tags. Students use it while learning HTML.
Need more customers from Google?
This tool is free and runs in your browser. If your business also needs more leads or sales, Google Ads is where people search with their wallet out. DeepRit is a Google Ads agency that does PPC and nothing else: we build the campaigns, block the searches that waste money, write the ads, set up conversion tracking and send you a short report every week. Request a free PPC audit and we will show you, in dollars, what we would fix first.
Indentation styles
Teams usually agree on an indentation style and use it everywhere. Two spaces is common in HTML, because pages are often deeply nested and wider indents push code off the screen. Four spaces is easier to scan for some people. Tabs let each developer choose how wide indentation looks in their editor. The HTML formatter supports all three, and many teams enforce their choice automatically with a code formatter in their editor or build process.
Privacy
Because the HTML formatter runs in your browser, the HTML you paste never leaves your device. That makes it safe to use with unpublished pages, internal tools or templates containing private details. Even so, avoid pasting secrets such as API keys into any web tool.
Formatting and whitespace
In most cases, browsers collapse runs of spaces and line breaks in HTML text into a single space, which is why formatting doesn't change how a page looks. There are exceptions: inside pre and textarea, and in elements styled with CSS white-space rules such as pre-wrap, whitespace is shown as written. Whitespace between inline-block elements can also create small visible gaps. That's why the HTML formatter keeps pre and textarea untouched and keeps inline content together; still, check the rendered page after formatting anything unusual.
Common mistakes
- Formatting the contents of pre or textarea, which changes what users see.
- Splitting inline elements onto new lines, which can add unwanted spaces.
- Minifying during development, which makes debugging harder. Minify only for production.
- Assuming formatting fixes invalid HTML. It shows problems; you still need to fix them.
Formatting HTML for email
HTML emails are often built with nested tables and inline styles, and email builders export them as long, dense lines. Running the export through the HTML formatter makes the table structure visible, so you can find the cell that holds a button or the row that adds unwanted spacing. When you're done, keep the formatted version for editing and send the original or a minified copy, because some email clients add their own limits on line length or message size, and extra whitespace adds nothing for readers.
Formatting before code review
Readable markup makes code review faster. If a template has been edited many times by different people, indentation can drift until the structure is hard to follow. Formatting it once, in a separate change that touches only whitespace, makes later changes much easier to review. Many teams then run a formatter automatically on every commit so the style never drifts again. Use the HTML formatter for one-off clean-ups, and set up an editor or build-tool formatter for ongoing work.
Sources and further reading
- MDN Web Docs: HTML: HyperText Markup Language, a complete reference for HTML elements.
- MDN Web Docs: Void element, the elements that have no closing tag.
- Minification (programming) on Wikipedia: why and how code is minified.
Frequently asked questions
What does an HTML formatter do?
It adds line breaks and indentation so the structure of the HTML is easy to read, or removes whitespace to minify it.
Does formatting change how my page looks?
Normally not, because browsers collapse whitespace. Content in pre and textarea is left untouched to be safe.
Is my HTML uploaded anywhere?
No. The formatter runs entirely in your browser.
Should I minify my HTML?
For production, it can help a little, especially without server compression. Keep the readable version for editing.
Can it fix broken HTML?
It can reveal structural problems and warns about unclosed tags, but you need to fix them yourself.
Is the HTML formatter free?
Yes. It's free, needs no sign-up, and works in your browser.
Free PPC audit
See where your ad budget leaks.
We look at your Google Ads account before the call, then walk you through what we'd fix first, in dollars. No obligation, no hard sell.