HTML Formatter

Format HTML markup.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

About this tool

Paste compact HTML and get it back with each block element on its own line and nested indentation. Inline tags such as b, a and span stay with their text, and the contents of pre, script and style are kept as written.

How to use

1
Step 1
Paste your HTML into the Input box.
2
Step 2
Press Run.
3
Step 3
Copy the formatted markup.

How it works

The markup is tokenised into tags, text and comments. Block elements open and close indented levels, inline elements and text are gathered on one line, and a block that holds only a short run of inline content is collapsed to a single line. Void tags such as br and img need no closing tag.

Worked example

A list with a link

Input
<ul><li>One</li><li><a href="/b">Two</a></li></ul>
Output
<ul> <li>One</li> <li><a href="/b">Two</a></li> </ul>
Walkthrough
The list items are indented and the link stays inside its li.

Limitations

  • It does not validate HTML or fix unclosed tags.
  • Whitespace inside text is collapsed to single spaces, except in pre and textarea.
  • Inline elements are never broken across lines.

Questions

Are pre and script contents changed?
No, they are kept as written.
Does it keep inline tags with text?
Yes, b, a, span and similar tags stay on the same line.
Will it fix broken HTML?
No, only layout changes.
Is my HTML uploaded?
No. The HTML is formatted in your browser and is never sent to a server.

Features

  • Nested indentation
  • Inline tags kept together
  • pre/script/style preserved
  • Runs in your browser

Related resources

Guides and videos from around the web—opens on YouTube or the publisher’s site.

  • TypeScript in 100 Seconds

    Fireship

    Formatted code is easier to skim while learning typed JS.

    Watch on YouTube
  • Learn JSON - Full Crash Course for Beginners

    freeCodeCamp.org

    Formatted JSON is easier to read once you know the structure.

    Watch on YouTube