What is HTML? Formatter, beautifier and minifier explained
Open the source of any web page and you will see the same pattern repeated thousands of times: an opening tag such as <section>, some content, and a matching closing tag, with more elements nested inside. That nesting is the page. A browser reads it top to bottom, builds a tree of elements called the DOM, and renders the result. People, unfortunately, often meet HTML in its least readable form: minified into a handful of enormous lines by a build tool, copied out of an email template, generated by a content management system, or written in a hurry with whatever indentation happened to come out of the keyboard. The structure is all there; it is just impossible to see.
People search for this tool under several names - html formatter, html beautifier, format html online, html minifier - and they are all describing the two directions of the same job. This page covers both directions, plus the checks that make them safe: void elements are never given closing tags, raw-text content is never re-indented, and broken markup produces a warning instead of a quiet rewrite. If you work with data rather than pages, the companion JSON Formatter applies the same philosophy to JSON.
How this HTML formatter works
Paste markup into the box, choose an indent - 2 spaces, 4 spaces or a tab - and press Beautify. Behind the button, the tool first splits your text into tokens: tags, text, comments, the doctype, and complete raw-text blocks for script, style, pre and textarea elements. Splitting carefully matters more than it sounds. A greater-than sign inside a quoted attribute value is not the end of a tag, and a closing tag mentioned inside a script is not markup at all. The scanner respects quoted attribute values and treats raw-text content as opaque text until the real closing tag arrives, which is exactly how the HTML specification says a browser reads the same input.
Beautify then walks the tokens with a depth counter. A block-level opening tag starts a new line and increases the depth; its closing tag decreases it; inline elements and text stay on the line they belong to, so a paragraph with a link and some bold text remains one readable line. Minify walks the same tokens and simply declines to print the optional whitespace: line breaks and indentation between block elements disappear, runs of whitespace inside text collapse to a single space, and comments are removed only if you ticked the option. Finally, a separate balance check replays the tag stack and reports any element that was opened but never closed - before you trust the output.
How to beautify or minify HTML step by step
To beautify: paste a full page or any fragment - a form, a table, a navigation list - into the input box. Choose the indent your project already uses; 2 spaces is the safe default for web work. Press Beautify and the formatted markup appears on the right, with the output byte count and the percentage change underneath. Because indentation adds characters, a beautified file is normally larger than the one you pasted, and that is expected: you are buying readability with spaces.
To minify: paste the finished markup, decide about comments, and press Minify. With the remove comments option off, comments survive and only whitespace is stripped; with it on, ordinary comments are removed too, while conditional comments for old browsers are always kept. The percentage under the result tells you exactly how much smaller the file became, so you can judge whether minifying a particular page is worth doing at all.
If a warning appears: read it before copying anything. The warning names the unclosed or mismatched tag, which is almost always a real mistake in the source - a div that was never closed during an edit, or a closing tag left behind after its element was deleted. Fix it in your original, paste again, and format the corrected version. The tool will format imperfect markup as best it can, but the warning is the valuable part.
Beautify, minify or leave it alone - which do you need?
Minifying earns its keep at exactly one moment: publication. A page that humans have finished editing and machines are about to serve is carrying whitespace that only humans needed. Email templates are the other strong case, because some email systems clip large messages, and every kilobyte of indentation is a kilobyte closer to the clip. The honest limits matter too, and a later section covers them: compression usually saves more than minification, and minified files are miserable to edit, so always keep the readable original as your source of truth.
Block, inline and void elements: the rules the formatter follows
HTML elements fall into families, and a formatter has to know which family each tag belongs to before it can decide where line breaks belong. Put a line break in the wrong place and, as the whitespace section explains, you can change what the page looks like. Keep an inline element glued to its text and the paragraph reads naturally. The table below is the classification this tool applies, drawn from the MDN element reference and the WHATWG syntax rules listed in the sources.
| Family | Examples | Formatter behaviour |
|---|---|---|
| Block elements | div, p, section, article, header, footer, ul, li, table, form, h1 to h6 | Start on a new line, indented by depth; children indent one level deeper |
| Inline elements | a, strong, em, span, code, small, sub, sup | Stay on the current line with the text around them; never split onto their own line |
| Void elements | br, img, input, meta, link, hr, source, wbr | Printed as a single tag; a closing tag is never invented for them |
| Raw-text elements | script, style, pre, textarea | Opening tag, content and closing tag copied exactly as written, in both modes |
| Comments and doctype | <!-- note -->, <!DOCTYPE html> | Preserved on their own lines in Beautify; comments removable in Minify on request |
Raw-text elements: script, style, pre and textarea
The HTML specification handles this by defining these as raw text or escapable raw text elements: once the opening tag is read, everything is plain text until the matching closing tag appears. This formatter implements the same rule directly. When the scanner meets one of these opening tags, it captures the whole block, opening tag to closing tag, as a single untouched unit. In Beautify the block is placed at the correct indent, but only its first line receives that indent - the remaining lines are the author's own. In Minify the block passes through unchanged, even when the rest of the page is being compressed around it. The practical result is simple: you can format a complete page, scripts and all, without wondering what happened inside them.
The whitespace caveat: when formatting can change rendering
Honesty about this point separates a formatter you can trust from one you cannot. The common claim that formatting never changes rendering is mostly true and quietly incomplete. HTML collapses sequences of whitespace into a single space in ordinary text, which is why re-indenting block structure is safe: the extra spaces sit between block boxes that ignore them. The exception is whitespace between inline-level boxes. Two spans separated by a newline in the source are separated by a rendered space on the page. Two inline-block cards, carefully sized to sit side by side at exactly half the container width each, will wrap onto two lines if a space appears between them - a classic bug that has frustrated many developers, and one a careless formatter can introduce.
This tool is built to avoid creating that bug. Inline elements and the text around them are never split across lines, so beautifying cannot insert a new line break where two inline elements touched. Minify is equally careful in the other direction: a whitespace-only gap between two inline elements collapses to one space rather than vanishing, because deleting it would join words and change text. Where the risk cannot be engineered away is a page whose CSS redefines elements - a span styled as a block, a div styled as inline - because the formatter reads markup, not stylesheets. For such pages, format a copy, preview it, and compare before you publish. That is not a weakness unique to this tool; it is the correct, honest boundary of every HTML formatter.
Common HTML formatting problems and how to fix them
| Problem | What you see | Fix |
|---|---|---|
| Mixed tabs and spaces | Markup that lines up in one editor and staircases in another | Reformat once with a single indent style and keep it for the whole project |
| Unclosed element | Everything after a point indents one level too deep; layouts swallow siblings | Find the tag named in the warning and close it where its content actually ends |
| Stray closing tag | A closing tag with no opener, usually left over from a deleted element | Delete the stray tag; the balance check flags it as unmatched |
| Inline elements split apart | Mystery gaps between buttons, menu items or inline-block cards | Keep inline runs on one line, as this formatter does, and remove source line breaks between them if a gap persists |
| Deeply nested markup | Lines starting far to the right and wrapping constantly | Use 2-space indent, and treat extreme depth as a design smell worth simplifying |
| Formatting inside pre or script | Broken code samples, shifted diagrams, altered form defaults | Never re-indent raw-text content; this tool preserves those blocks automatically |
Minifying HTML in production: the honest gains
It would be easy to sell minification as a dramatic speed feature. The truth is smaller and still worth having. The whitespace in a carefully indented page is real bytes, and on a large page - a long documentation page, a dense application shell, an email template - removing it can save a noticeable share of the HTML itself. The percentage readout under the result exists precisely so you can see your own number instead of trusting a general claim: if minifying a page saves 4 percent, you will see 4 percent, and you can decide with open eyes whether the step is worth it for that page.
| Technique | What it removes | Typical effect on an HTML file |
|---|---|---|
| Minify (this tool) | Indentation, blank lines, optional whitespace; comments on request | Modest - varies with how heavily the source was indented |
| gzip or Brotli compression | Repeated patterns across the whole response, applied by the server | Large - usually the single biggest saving available for text |
| Removing unused markup | Dead sections, commented-out blocks, unused template branches | Varies - sometimes the largest saving of all, and it needs a human decision |
Malformed HTML: warnings, not silent repairs
So this formatter takes the other path. Its balance check tracks every non-void element as it opens and closes. A closing tag with no opener is reported. A closing tag reached while a child is still open is reported, with the child named. Anything still open at the end of the input is reported by name. The formatted output is still produced - the tool formats what it could read and does not add closing tags of its own - and the warning travels with it, so the state of the markup is never a secret. The fix is then yours, made in the right place: usually adding one closing tag where the content genuinely ends, or deleting a leftover closer. Format again and the warning is gone, which is the most satisfying confirmation a formatter can give.
Your HTML stays in your browser
Page source is more sensitive than it looks. An unpublished landing page, the markup of an internal admin screen, a template with a signed URL or a form carrying a token - all of these pass through formatter tools every day, and a tool that uploads them to a server is asking for more trust than the job requires. This page never asks: the code that formats your HTML is delivered with the page itself and runs locally, so the markup you paste exists only in your browser's memory. The flip side is worth stating plainly too. Because nothing is stored, nothing is saved for you: close or refresh the tab and your input and output are gone, so copy or download the result before you leave. For working with the data formats that live inside pages, see the companion JSON Formatter, which follows the same in-browser rule.
Sources & References
The rules this guide describes are written down in the references below. All seven were checked and returned HTTP 200 on the day this page was built. No substitutions were needed: every source listed here is the source that was intended, covering the MDN HTML reference, the WHATWG HTML Living Standard and the W3C standards home.
- MDN Web Docs - HTML: HyperText Markup Language - the reference overview of HTML, its elements and how documents are structured - the starting point for everything this guide describes.
- MDN Web Docs - HTML elements reference - the complete element-by-element reference used to classify block, inline and void elements in the table below.
- MDN Web Docs - Void element (Glossary) - the definition this tool follows: a void element cannot have content and must not have an end tag.
- WHATWG HTML Living Standard - The HTML syntax - the normative syntax rules for tags, void elements, raw text elements and the doctype that this formatter preserves.
- WHATWG HTML Living Standard - Parsing HTML documents - how browsers actually parse markup, including the error recovery that inspired this tool's warn-rather-than-guess behaviour.
- MDN Web Docs - The script element - why script content is raw text whose characters must never be re-indented or treated as markup.
- W3C - HTML and CSS standards - the W3C home for the web design standards family that HTML belongs to, including links to validation and accessibility resources.