Frontend ToolsA little help for every day

Search by name or task, such as JSON or percentage.

Frontend Tools

HTML Beautifier and Formatter

Format minified HTML with clean indentation. Void elements add no depth, short elements stay on one line, pre content is kept, and inline CSS and JS are tidied.

View all tools
ResultUpdates as you type
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Demo</title>
    <style>
      body {
        margin: 0;
        color: #333;
      }
    </style>
  </head>
  <body>
    <main>
      <h1>Hello</h1>
      <p>Some <b>bold</b> text<br>and a line break.<img src="a.png" alt=""></p>
      <ul>
        <li><a href="/">Home</a></li>
        <li><a href="/about">About</a></li>
      </ul>
      <pre>  keep   spacing</pre>
    </main>
  </body>
</html>

Void elements such as br, img, input and meta don't add indentation; pre and textarea content and the spaces between inline elements are kept; omitted end tags (such as </p> or </li>) are left as they are.

How to use HTML Beautifier and Formatter

Paste HTML into the box and the formatted version appears beside it. Choose 2 spaces, 4 spaces or tabs, set the maximum line length and decide whether style and script blocks are formatted too.

  1. Paste the HTMLPaste a fragment or a full page, even one that has been minified onto a single line.
  2. Set indent and line lengthPick 2 spaces, 4 spaces or Tab, and a max line length from 40 to 400 characters (100 by default).
  3. Copy the formatted codeLeave the style and script option ticked to tidy inline CSS, JavaScript and JSON, then copy.

How the layout is decided

Block elements each start on a new line and are indented one level per nesting depth. An element holding only text or inline elements, such as an h1, an li or a short paragraph, stays on one line if it fits within the max line length; otherwise its content moves to its own indented line. Inline elements like a, b and span stay in the flow of text with the spaces between them kept, so the page renders the same. In the sample page, html, head, body, main and ul open out over several lines, while the h1, each li and the paragraph containing br and img stay on one line each.

Void elements, pre blocks and missing end tags

Void elements such as br, img, input, meta and link never add indentation, so lines don't drift further right after every image. Text inside pre, textarea and title is kept exactly. With the inline option on, CSS in style blocks, JavaScript in script blocks and JSON such as JSON-LD are formatted with the same indent; untick it to leave them as they are. Optional end tags are understood when working out nesting, so an li or p without its closing tag is still placed correctly, but missing end tags are not added for you.

Accuracy and data handling

After adding generated code to a project, test it in the target browsers and responsive sizes. The calculation runs in your current browser; the tool code does not send the input to a processing API.

Often Used Together

Next step

FAQ

Will formatting change how my page looks?

Normally not. Line breaks and indentation are only added between block elements, the spaces between inline elements are kept, and pre and textarea content is left untouched.

Why are some elements kept on one line?

Elements containing only text or inline content stay on one line when they fit within the max line length. Lower the max line length, down to 40, to open more of them out.

What's the difference between an HTML beautifier and a minifier?

A beautifier adds line breaks and indentation so code is easy to read and debug. A minifier removes comments and spare whitespace to cut file size. The HTML Minifier on this site does the reverse job.

More Frontend Tools

Related tools