HTML Formatter

Paste an HTML document or fragment to indent it so the element nesting is easy to read. The formatter accounts for whitespace-sensitive markup. It skips internal formatting of embedded JavaScript and CSS, though their surrounding indentation can change. Everything runs in your browser and your input stays on this device.

What this tool does

Format HTML source into a readable document or fragment with clearer element nesting.

Does formatting change how the page renders?

Usually the rendering stays the same, but whitespace between inline elements and inside preformatted text can be visible. The formatter accounts for whitespace-sensitive markup using CSS display defaults. Compare the original and formatted rendering if your markup depends on spacing or custom CSS.

When to use it

Indentation helps expose a misplaced container in a rendered response while keeping the original markup available for comparison.

How to use it

  1. Paste a document or fragment as source text.
  2. Choose Format HTML and review the indentation.
  3. Compare the original and formatted rendering when inline whitespace matters.

Worked example

Load the sample main element containing an article, heading and paragraph. Format it and look for article nested inside main, with the heading and paragraph aligned at the same indentation level. Copy the result into a test fixture and compare the nesting with the DOM in your browser. If you are formatting a whole document, check that head and body still contain the intended elements. Keep the original nearby when reviewing markup where line breaks affect rendering.

Example input
<main><p>Ready</p><p>Queued</p></main>
Example output
<main>
  <p>Ready</p>
  <p>Queued</p>
</main>

Supported features and limitations

The tool displays source as text. It skips internal formatting of embedded JavaScript and CSS. Use the CSS Minifier for a stylesheet.

Common mistakes and edge cases

Whitespace can be visible between inline elements or inside preformatted text. Compare both source and rendering if your markup relies on that spacing. Framework templates can contain delimiters or syntax that requires a template-aware formatter. Review these files with the formatter recommended by the framework before replacing them. A pasted fragment can contain valid markup for its eventual parent even when it looks incomplete as a standalone document. When reviewing a layout issue, start with the smallest fragment that reproduces it. Preserve the elements around the problem when testing, because a parent element or surrounding inline text can change how whitespace is displayed.

Frequently asked questions

Will pasted scripts execute?
The tool shows HTML as text. Script tags in the input are part of that source, so use your normal security and review process before inserting output into a live page.
Can this fix accessibility errors?
Formatting makes structure easier to review. Use accessibility checks to evaluate labels, landmark structure, heading order and keyboard behavior in the running page. A formatter cannot determine whether the text and interactions meet the needs of your audience.
How do I format HTML online?
Paste a document or fragment, choose Format HTML, review the indentation, then copy or download the result.
Can I format a fragment instead of a full document?
Yes. Paste an HTML fragment without adding a full document wrapper. A fragment may be valid in the parent element where you intend to place it.
Does it format the JavaScript and CSS inside my page?
Internal formatting of embedded JavaScript and CSS is skipped. The formatter can still adjust surrounding indentation and line breaks.
Is my HTML uploaded anywhere?
No. It is processed in your browser and stays on your device.

Related tools

Developer guides