Home › Developer Tools › HTML Formatter

HTML Formatter

Paste HTML to beautify it with clean indentation, wrap long lines or minify it, and check the result in a live preview. Code inside <pre>, <textarea>, <script> and <style> is handled carefully.

Last updated:

Input HTML
Waiting for HTML…

      
      

Everything runs in your browser. The preview is sandboxed: scripts, forms and pop-ups are blocked.

Advertisement
Advertisement

How to use the HTML Formatter

  1. Paste your HTML into the input box or open an .html file. Press Sample to try it.
  2. Choose the indentation and line wrap, and whether the contents of <head> and <body> get an extra indent.
  3. Press Format HTML. The output updates as you type while Live is on.
  4. Open the Preview tab to see how the page renders. Scripts do not run in the preview.
  5. Copy or download the result, or press Minify for a compact version.

Before and after

Input:

<ul class="menu"><li><a href="/">Home</a></li><li><a href="/blog/">Blog</a></li></ul><p>Read the <strong>latest</strong> post.</p>

Formatted with 2 spaces:

<ul class="menu">
  <li><a href="/">Home</a></li>
  <li><a href="/blog/">Blog</a></li>
</ul>
<p>Read the <strong>latest</strong> post.</p>

How the formatter treats each kind of content

ContentWhat happensWhy
Block elements (div, p, ul, table, section…)Own line, children indented one levelWhitespace between blocks does not affect rendering
Inline elements (a, strong, em, span, img…)Stay on the text lineAdding line breaks inside text would add visible spaces
<pre> and <textarea>Copied exactlyEvery space and line break inside them is displayed
<style>CSS is formatted rule by ruleReadable embedded styles
<script>Re-indented as a block, code unchanged; JSON-LD is pretty-printedChanging JavaScript beyond indentation could break it
Comments and DOCTYPEKept on their own lineConditional comments and notes stay intact

Elements whose end tags are optional in HTML, such as <li>, <p>, <td> and <option>, are closed the same way a browser would close them. The status bar warns about tags that are never closed and closing tags with no matching opening tag, which are the most common causes of broken layouts.

Indentation and line length tips

  • 2 spaces is the most common style for HTML because pages nest deeply. Use tabs if your team or editor prefers them.
  • Wrap at 80 or 120 characters to split long paragraphs over several lines. Lines only break at spaces in text, never inside a tag or attribute.
  • Indent head & body controls whether <head> and <body> are indented inside <html>. Many style guides leave them flush to save one level.
  • Formatting is not validation. For full HTML validation, use the W3C Markup Validation Service after tidying the code here.

Frequently asked questions

What does an HTML formatter do?

It re-indents HTML so that each nested block element starts on its own line, one level deeper than its parent. This makes the structure of a page easy to see, helps you spot unclosed tags and makes code reviews simpler. The page looks the same in the browser.

Will formatting change how my page looks?

No in almost all cases. Whitespace between block elements is ignored by browsers, inline elements such as links and bold text are kept on the same line as the surrounding text, and content inside <pre> and <textarea> is never touched. Rare layouts that depend on whitespace between inline-block elements can shift by a few pixels.

Is the live preview safe?

Yes. The preview is shown in a sandboxed iframe without permission to run scripts, submit forms or open pop-ups. Images and stylesheets from absolute URLs load; relative links cannot be resolved because the preview has no base address.

Can I unminify HTML?

Yes. Paste minified HTML, for example from a page's source, and press Format HTML. Every block element is put back on its own line with indentation. Removed comments cannot be recovered.

What does Minify do?

Minify removes comments (except conditional comments), collapses runs of spaces and line breaks into a single space and drops whitespace between block elements. Content in <pre>, <textarea> and <script> is kept as it is, and embedded CSS is minified.

Is my HTML uploaded?

No. Formatting and the preview happen entirely in your browser. Your code is never sent to a server.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

CSS FormatterBeautify CSS with indent controls and optional property sorting.XML FormatterBeautify, validate and minify XML with a collapsible tree view.JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.HTML Entity Encoder / DecoderEscape and unescape HTML entities, named or numeric.Image Alt Text GeneratorGenerate descriptive alt text for images with an AI captioning model in your browser. Edit, copy.Code Diff CheckerCompare two code files side by side or unified, with syntax colors and changes highlighted.CSS Animation GeneratorCreate CSS keyframe animations from 23 presets with live preview, timing controls and Copy CSS.CSS Border Radius GeneratorRound each corner, draw elliptical 8-value radii or random blob shapes and copy the CSS.ZIP File CreatorCompress files and folders into a ZIP.YAML Validator & FormatterValidate, format and minify YAML, and convert YAML to JSON or back.JSON MinifierMinify and validate JSON, sort keys and see exactly how many bytes you save.IPv6 Expander & CompressorExpand IPv6 addresses to full form or compress them per RFC 5952, one or many at once.GraphQL FormatterPretty-print and indent GraphQL queries, mutations and schemas, or minify them, instantly.CSS ValidatorValidate CSS: syntax errors, unknown properties and invalid values by line, plus auto-fix.Gzip Compress / DecompressGzip or deflate text and files, get Base64 output, and decompress Base64 or .gz files.IBAN ValidatorCheck an IBAN's mod-97 checksum, country and length, and see its bank code and account parts.JavaScript Syntax CheckerCheck JavaScript for syntax errors with line and column, for any ES version, script or module.JSON Schema ValidatorValidate JSON against a JSON Schema (draft-07, 2019-09, 2020-12) with clickable error paths.Markdown FormatterBeautify Markdown with Prettier: list markers, prose wrap, aligned tables and live preview.PHP FormatterBeautify PHP code with Prettier PHP: PSR-12 style, indent and brace options, syntax errors.TypeScript FormatterFormat TypeScript and TSX code with Prettier: width, tabs, semicolons and quotes options.XML MinifierMinify and validate XML: strip whitespace and comments, keep CDATA, see the size savings.C# FormatterBeautify C# code online: Allman or K&R braces, indent size and line width, clang-format option.HTML ValidatorCheck HTML for errors and warnings with line numbers, locally or with the W3C Nu checker.Java FormatterBeautify Java code online: indent size, brace style and line width, with clang-format option.JavaScript ObfuscatorObfuscate JavaScript with string encoding, renaming and control-flow flattening presets.Phone Number FormatterFormat and validate lists of phone numbers to E.164, international or national style.Python FormatterFormat Python code in Black/Ruff style: line length, quote style, indent, copy or download.Responsive Design CheckerPreview any website at phone, tablet, laptop and desktop sizes side by side, with rotate and zoom.Browser Compatibility CheckerSearch CSS, JavaScript and HTML features and see which browser versions support them.Core Web Vitals CheckerCheck real-user LCP, INP and CLS for any URL or site and see if it passes Core Web Vitals.Heading Structure CheckerPaste HTML to see its H1-H6 outline and catch missing H1s, multiple H1s and skipped levels.Website Hosting CheckerFind out who hosts a website: hosting provider, IP addresses, ASN, network owner and location.Routing Number ValidatorCheck a US ABA routing number's checksum and format and see its Federal Reserve district.Spam Word CheckerScan an email subject and body for spam trigger words, excess caps, exclamation marks and risky links.Check Digit CalculatorCalculate or validate check digits for UPC, EAN, GTIN, SSCC, ISBN, ISSN and mod 11 codes.Luhn Algorithm CheckerValidate numbers with the Luhn mod 10 check or calculate the missing check digit, step by step.XSD ValidatorValidate XML against an XSD schema in your browser and see each error with its line number.Strftime Format BuilderBuild Python and C strftime format strings by clicking tokens, with a live preview and reference.
See all 41 Code Formatters & Validators →