What is HTML? Formatter, beautifier and minifier explained

Quick answer: HTML is the markup language every web page is written in: elements wrapped in tags describe headings, paragraphs, links, images and forms. An html formatter - also called an html beautifier - re-prints that markup with consistent indentation so people can read it. An html minifier does the reverse, stripping optional whitespace so the file is smaller. This page does both, entirely in your browser.

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

Quick answer: The page scans your markup tag by tag in your browser, classifies each element as block, inline, void or raw-text, and re-prints it: block elements on their own indented lines, inline content kept together, raw-text content copied word for word. Minify removes whitespace between block elements and, if you choose, comments. A balance check warns about unclosed tags instead of guessing.

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

Quick answer: Paste your HTML into the box on the left, pick an indent, then press Beautify to make it readable or Minify to shrink it. Read the byte counts under the result to see the size change, check for any warning about unclosed tags, then finish with Copy Output or Download .html.

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?

Quick answer: Beautify markup you are about to read, debug or edit. Minify markup that is finished and about to be published or sent. Leave generated markup alone while a template engine or build tool owns it - format the output when you need to inspect it, not the template that produced it.

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.

Should I beautify HTML that a framework generates?
Beautify the generated output when you need to inspect or debug it, yes - that is often the only way to see what your components actually produced. Do not paste the beautified output back into your project as a replacement for templates or components, because the next build will overwrite it and your formatting work will be lost.

Block, inline and void elements: the rules the formatter follows

Quick answer: Block elements such as div, p and section each get their own indented line. Inline elements such as a, strong and span stay inside the line of text they belong to. Void elements such as img, br and input are complete in a single tag and are never given a closing tag. Those three rules produce almost all of the output you see.

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.

FamilyExamplesFormatter behaviour
Block elementsdiv, p, section, article, header, footer, ul, li, table, form, h1 to h6Start on a new line, indented by depth; children indent one level deeper
Inline elementsa, strong, em, span, code, small, sub, supStay on the current line with the text around them; never split onto their own line
Void elementsbr, img, input, meta, link, hr, source, wbrPrinted as a single tag; a closing tag is never invented for them
Raw-text elementsscript, style, pre, textareaOpening 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

Quick answer: Inside script, style, pre and textarea, the text is not ordinary markup and whitespace is part of the meaning. This tool copies everything between those opening and closing tags exactly as written - no re-indenting in Beautify, no whitespace removal in Minify - so code, styles and preformatted text survive formatting byte for byte.

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

Quick answer: Browsers collapse most whitespace, so beautifying is normally render-neutral - but not always. A line break inserted between two inline elements renders as a space, and in inline-block layouts that space can push elements apart or wrap a row. This tool keeps inline content on one line to minimise the risk; still, preview any page where inline spacing is load-bearing.

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

Quick answer: Most formatting trouble comes from five causes: mixed tabs and spaces, nesting so deep the indentation runs off the page, unclosed tags from hand editing, copied markup carrying a previous project's indent style, and inline elements split across lines. The fixes are consistent indentation, a balance warning you actually read, and formatting before you edit rather than after.
ProblemWhat you seeFix
Mixed tabs and spacesMarkup that lines up in one editor and staircases in anotherReformat once with a single indent style and keep it for the whole project
Unclosed elementEverything after a point indents one level too deep; layouts swallow siblingsFind the tag named in the warning and close it where its content actually ends
Stray closing tagA closing tag with no opener, usually left over from a deleted elementDelete the stray tag; the balance check flags it as unmatched
Inline elements split apartMystery gaps between buttons, menu items or inline-block cardsKeep inline runs on one line, as this formatter does, and remove source line breaks between them if a gap persists
Deeply nested markupLines starting far to the right and wrapping constantlyUse 2-space indent, and treat extreme depth as a design smell worth simplifying
Formatting inside pre or scriptBroken code samples, shifted diagrams, altered form defaultsNever re-indent raw-text content; this tool preserves those blocks automatically

Minifying HTML in production: the honest gains

Quick answer: Minifying a hand-written HTML page typically removes the indentation and blank lines that make up a modest slice of the file - this tool shows your exact figure before you decide. Compression such as gzip or Brotli usually saves several times more, so minify as a finishing step, keep the readable original, and never minify the only copy.

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.

TechniqueWhat it removesTypical effect on an HTML file
Minify (this tool)Indentation, blank lines, optional whitespace; comments on requestModest - varies with how heavily the source was indented
gzip or Brotli compressionRepeated patterns across the whole response, applied by the serverLarge - usually the single biggest saving available for text
Removing unused markupDead sections, commented-out blocks, unused template branchesVaries - sometimes the largest saving of all, and it needs a human decision
Is it safe to minify HTML that contains inline scripts?
With this tool, yes: script blocks are raw-text and pass through minification completely unchanged, so a script that depends on its own spacing or strings is never touched. The caution applies to aggressive minifiers that also rewrite JavaScript - that is a different operation, with real breakage risk, and it is not what this page does.

Malformed HTML: warnings, not silent repairs

Quick answer: If tags are unclosed or mismatched, this tool names them in a warning and formats only what it could read, without inventing closing tags or dropping content. Browsers hide the same mistakes by guessing a repair, which is fine for display and dangerous in a file you are about to publish - the warning tells you what the browser would never mention.

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

Quick answer: Tokenising, beautifying, minifying and counting all run in this tab, on your device. Nothing you paste is transmitted or stored - which makes the page safe for unpublished designs, internal admin markup and templates containing tokens - and nothing is kept for you either: refresh the tab and both boxes are empty.

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.