Skip to content
cliplimeClipLime

Format and beautify HTML

Paste HTML, even a minified page, and get it indented so the structure is easy to read. Nothing leaves this tab.

Your text is processed in this tab and never uploaded

Options

Off leaves what is between the tags exactly as written.

Off keeps head and body level with html.

0 characters, 0 lines Your text stays in this tab.

This lays out the markup. It does not check that the HTML is valid, and it never adds, removes or fixes a tag. Text in pre and textarea is left alone.

At a glance

What it does
Indents HTML so the structure is easy to read, as you type.
Options
2 or 4 spaces or tabs, wrapping at 80 or 120 characters, attribute wrapping, and indenting head and body.
Inline code
Formats CSS inside style tags and JavaScript inside script tags, or leaves them as written.
Left alone
Text inside pre and textarea.
Works on
Whole pages and fragments, including minified HTML copied from a site.
Not checked
It does not validate the HTML or fix tags. Unclosed tags are not reported.
Privacy
Runs in your browser tab. Your HTML is never uploaded.

How to do it

  1. 1

    Paste your HTML

    Paste a page or a fragment into the left box, drop an .html file on it, or press Example.

  2. 2

    Choose a layout

    Pick the indent, whether long lines wrap, and how attributes are written. Turn off Format code inside style and script to leave those blocks as written.

  3. 3

    Read the result

    The formatted HTML updates as you type.

  4. 4

    Copy or download

    Copy the result or download it as formatted.html.

How block and inline elements are treated

HTML elements fall into two groups. Block elements, such as div, p, ul, section and table, start on a new line, so the formatter puts each on its own line and indents its children. Inline elements, such as a, span, strong, em, img and button, sit inside a line of text, so they stay in the line with their words.

Keeping inline elements in the text matters. A space between two inline elements shows up on the page, and a missing space does too. The formatter does not add white space between inline elements that touch in your source.

Text inside pre and textarea is copied exactly, because white space is part of its content.

When formatting can change how a page looks

Browsers collapse runs of white space, so re-indenting markup normally changes nothing on screen. There are a few places where it can:

  • Between inline-block elements such as buttons or images laid out in a row, where a line break between tags renders as a small gap.
  • Inside elements styled with white-space: pre or pre-wrap, which keep their line breaks.
  • In text that a script reads back from the page with innerHTML or textContent.

If the page depends on any of these, compare it before and after. Wrapping long lines at 80 or 120 characters moves text between lines but does not change the words.

Style and script blocks

By default the CSS inside style tags and the JavaScript inside script tags are formatted with the same engines as the CSS formatter and the JavaScript formatter. Turn the option off to keep those blocks exactly as written, for example when they contain a template language.

Template tags such as {{ name }}, {% if %} and <% %> are kept as text. The layout around them can be rough, because the formatter does not understand the template language.

Formatting is not validating

This tool lays out what you give it. It does not check that tags are closed or nested correctly, that attributes are valid, or that the page would pass a validator, and it never adds or removes a tag. After formatting, the result is compared with your input, and a note appears if anything other than white space differs. Browsers repair broken HTML silently, so a page can look fine and still have errors. For strict XML-style markup, such as XHTML or SVG, use the XML formatter, which reports mismatched tags.

Questions people ask

Does it fix broken HTML?

No. It never adds, removes or repairs a tag. Broken markup is laid out as it is read, and the result may look odd where the structure is wrong, which can help you spot the problem.

Can I format just a fragment?

Yes. A fragment such as a single div or a list of elements works without html and body tags.

Will it break my templates?

Template tags are kept as text, but the formatter does not understand them, so it may place line breaks in awkward spots. Review the result for templates where tags open or close HTML elements.

Can it minify HTML?

No. This tool formats. Minifying HTML safely needs to understand which white space matters in each element, and it is better done by your build tool.

What happens to code inside script and style?

By default it is formatted as JavaScript and CSS. Turn off Format code inside style and script to copy those blocks exactly as written.

Is my HTML uploaded?

No. The HTML formatter loads into your browser tab and runs there. Your markup is never sent anywhere.