Format / indent / read

HTML Formatter Online

Paste minified or messy HTML and get readable, consistently indented code, including the CSS in style blocks and the JavaScript in script blocks. The formatter runs in your browser, so your code never leaves your device.

Runs in your browser2 spaces, 4 spaces or tabsCopy or download the result
Try it here

Format your HTML

Paste HTML or open a local .html file, choose an indent style and select Format HTML. Copy or download the result and put it back in your project.

Options

Formatting uses the open-source js-beautify library (version 1.15), loaded into this page. Text inside <pre> and <textarea> is left exactly as written. Keep your original until you have compared the two versions.

HCODX / formatted HTML
HTML formatting

What an HTML formatter changes, and what it leaves alone

Formatting is a source-editing step. It rearranges whitespace so the structure is easy to read; elements, attributes and text stay the same.

HTML copied from a template, a CMS export, an email builder or a production page often arrives as one very long line. When dozens of elements share a line, it is easy to miss a closing tag or edit the wrong attribute. The formatter puts block-level elements such as div, section, ul and table on their own lines and indents their children, so the tree you read matches the tree the browser builds.

Style and script blocks are formatted too, using the CSS and JavaScript beautifiers from the same library, so an inline stylesheet ends up with one declaration per line. Inline elements such as a, b and span stay inside their sentence. Breaking them onto separate lines could add a visible space between words, so the formatter only adds line breaks where whitespace has no effect on the rendered page.

A formatter is not a validator. Neatly indented code can still contain duplicate IDs, an image without alt text or a label that points nowhere. Run the result through the HTML checker when you want those problems listed with line numbers, and keep testing the page itself in a browser.

See nesting

Indentation shows which parent each element belongs to, so a misplaced closing tag stands out.

Embedded CSS and JS

Style and script blocks are formatted with matching CSS and JavaScript rules.

Private by design

The formatter runs inside this page. Your HTML is not uploaded or stored.

Before and after

A compressed snippet, formatted

The same markup before and after formatting with a two-space indent.

In the compressed version it is hard to tell whether the list belongs inside the main element or follows it. After formatting, the answer is visible at a glance: ul is indented under main, and each li under ul.

The sentence inside the paragraph did not move, and neither did the link in the middle of it. The two adjacent span elements at the end also stay joined, because adding a line break between them would put a space between the letters on the page.

Formatter input and output
<!-- Input -->
<main><h1>Plan</h1><ul><li>Draft</li><li>Review</li></ul><p>Read the <a href="/guide/">guide</a> first.</p><span>a</span><span>b</span></main>

<!-- Output -->
<main>
  <h1>Plan</h1>
  <ul>
    <li>Draft</li>
    <li>Review</li>
  </ul>
  <p>Read the <a href="/guide/">guide</a> first.</p><span>a</span><span>b</span>
</main>
Workflow

Format a file safely in four steps

Formatting is low-risk, but a quick comparison keeps it that way.

Keep the original Commit the file or save a copy before replacing it with formatted code, so you can compare or roll back.
Paste or open the file Paste the markup above or choose Open file. A complete page and a fragment both work.
Match your project's style Pick the indent your project already uses, for example the value in its .editorconfig or Prettier settings.
Compare and replace Check that pre blocks, scripts and inline text look right in the output, then copy or download it.

If your repository already formats code automatically, for example with Prettier in a pre-commit hook, keep using that tool so formatting changes do not create noisy diffs.

Choose the right tool

Formatter, minifier or checker?

All three read the same HTML, but each answers a different question.

Edit

Formatter

Makes source readable for editing, code review and debugging. Use it on files people work on.

Ship

Minifier

Removes comments and spare whitespace for a smaller delivered file. Use it on output, not on the copy you edit.

Review

Checker

Lists unclosed tags, duplicate IDs, missing alt text and similar mistakes with their line numbers.

Questions

HTML formatter questions

No. The page loads the formatting library once and runs it in your browser. Your code is not sent to HCODX or anyone else, and nothing is saved after you close the tab.

Normally not. Line breaks are added between block-level elements, where whitespace does not render, and content inside pre and textarea is left exactly as written. If you style other elements with white-space: pre in CSS, compare those parts of the page before and after.

No. It indents what is there. A missing closing tag often shows up as indentation that drifts to the right and never comes back, which is a useful clue, but the fix is yours. The HTML checker lists such errors with their line numbers.

Use whatever your project already uses. Two spaces is common in front-end projects and keeps deeply nested markup readable; four spaces or tabs are equally valid. Consistency across files matters more than the choice itself.

With wrapping on, long runs of text and long attribute lists are broken at existing spaces near the chosen width. With Don't wrap, lines are only broken between elements, which keeps text searchable on a single line.

Yes. Paste the complete document from the doctype to the closing html tag. Untick the head and body option if you prefer those two levels flush left, a style some projects use to save horizontal space.

This tool expects HTML; CSS and JavaScript are formatted when they sit inside style and script tags. For separate .css and .js files, use the Format Code command in the HCODX editor, which handles all three languages.

Working on a whole project?

The HCODX editor keeps your HTML, CSS and JavaScript files together with a live preview, and has the same formatting command built in.

Instant HTML Runner & Viewer with Live Preview

Need to run a short HTML, CSS and JavaScript snippet? The HTML Runner Online has a focused editing surface with live output.

Open HTML Runner Online