Format Code Now
/

HTML Formatter and Minifier

FV-08

Paste HTML and press Format to indent it so each tag is easy to read, or Minify to remove comments and extra whitespace. Embedded CSS and JavaScript are handled too.

Runs in your browser. Nothing is uploaded.

HTML

Result

How to use it

  1. Paste your HTML into the input box, or open an .html file.
  2. Choose Format to indent the markup, or Minify to compress it.
  3. Pick 2 spaces, 4 spaces or Tab, and a wrap width if you want long lines broken.
  4. Untick Keep inline elements on the line if you want tags such as b and a on their own lines.
  5. Copy the result or download it as an .html file.

What Format does

Format puts block elements on their own lines and indents children one level, using 2 spaces, 4 spaces or a tab. The CSS inside <style> and the JavaScript inside <script> are formatted as well. Inline elements such as <a>, <b> and <span> stay on the line of the text around them unless you untick the option. A wrap width of 80, 100 or 120 breaks long lines of text. It does not repair broken HTML or add missing closing tags.

What Minify removes

Minify deletes comments, except IE conditional comments, collapses runs of spaces and line breaks, and removes whitespace between block-level tags and around the edges of the document. Spacing around inline tags is kept as one space, because removing it can join words. Text inside <pre> and <textarea> and the code inside <script> is left as written. CSS in <style> is minified. It does not shorten attribute values or remove optional tags.

Whitespace can change how a page looks

In HTML a run of spaces shows as one space, so extra whitespace can be removed safely in most places. The exceptions are <pre>, <textarea> and inline content, where a space between two words or tags is visible. That is why the formatter and the minifier are careful there. Always look at the page after minifying a template, especially one with inline-block elements that depend on the gaps between them.

Error messages and what to do

MessageWhat it meansFix
Comment starting at line 3 is never closed (missing -->).A <!-- comment has no ending -->.Add --> where the comment should end, or remove the stray <!--.
<script> opened at line 12 is never closed.A <script>, <style>, <pre> or <textarea> tag has no matching closing tag. The message names the tag.Add the closing tag. These tags must be closed because their contents are not read as HTML.

Questions people ask

How do I format HTML online?

Paste your HTML into the input box and choose Format. The output is indented with 2 spaces, 4 spaces or a tab, as you choose. Copy it or download an .html file. It runs in your browser and the HTML is not uploaded.

Does it format the CSS and JavaScript inside the page?

Yes. When you choose Format, the CSS in <style> tags and the JavaScript in <script> tags are re-indented along with the HTML. Minify also compresses <style> contents, but leaves JavaScript as written.

Will Minify break my page?

It is built to keep the page the same. It keeps <pre> and <textarea> text, scripts and one space around inline tags. Still, check the result, especially for layouts that depend on spaces between inline-block elements.

Can it fix invalid HTML?

No. It indents what you give it and does not add missing closing tags or correct nesting. Unclosed comments and unclosed script, style, pre and textarea tags are reported when you minify.

What does Keep inline elements on the line do?

When it is ticked, tags such as a, b, em and span stay with the text around them, so a sentence with a link stays on one line. When it is off, every element goes on its own line, which is longer but shows the structure.

Does it remove HTML comments?

Minify does, except IE conditional comments that start with <!--[if. Format keeps comments and indents them. If you need a comment to survive minifying, check the output first.

About this tool

Format uses the js-beautify library. It re-indents tags and also formats the CSS inside <style> and the JavaScript inside <script>. It does not fix broken HTML or add missing closing tags. Minify is our own: it removes comments (except IE conditional comments), collapses runs of whitespace and tidies spacing inside tags. Text inside <pre>, <textarea> and <script> is left as written, and <style> is minified. Whitespace between inline elements is kept as one space because removing it can change how the page looks.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.