Mr. Tools

How to

How to use the HTML Formatter

Paste HTML and it is formatted on the right right away. If something cannot be read, the line and column and the reason appear above the input box, and that line is marked. What you enter is never sent anywhere and stays only on this device.

HTML Formatter thumbnailHTML Formatter thumbnail
Steps
4 steps
Guide
With screenshots
Content
Notes and FAQ

Use Cases

When to use it

  • Make HTML crammed onto one line easy to read
  • Find where a closing tag is wrong
  • Minify HTML you publish to make it lighter
  • Tidy the HTML of an email or blog template

Capabilities

What this tool can do

  • Format pasted HTML right away (Indent space 2, Indent space 4, Indent tab)
  • Minify by removing spaces, line breaks and comments
  • Show where something cannot be read as a line and column, with the reason
  • Close unclosed tags for you
  • Format the contents of <style> and <script> too
  • Copy the result, or save it as formatted.html

Steps

Steps

The order of operations and checkpoints are listed so you can proceed while looking at the screen.

STEP 1

Paste your HTML

Paste HTML into the "Input" box on the left. While the box is empty, you can also press "Paste" in the bar at the bottom. There is no convert button: the formatted HTML appears in "Result" on the right right away. You can format a whole page or just part of one.

The input box and the result box outlined in red

Checkpoints

  • Formatted HTML appeared in "Result" on the right
  • No red band is showing above the input box

Where to look on screen

01
Paste and sample

"Paste" puts in the HTML you have copied, as it is. To try the tool, "Insert sample" puts in a sample HTML.

"Paste" and "Insert sample" in the bottom bar outlined in red

STEP 2

Fix any errors

If something cannot be read, a red band appears above the input box showing where and why, for example "Line 3, column 1: There is a closing tag </ol> without a matching opening tag". That line gets a red mark. Fix it as the band says, and the band goes away and the result appears.

The error band and the marked line outlined in red

Checkpoints

  • The red band is gone
  • Formatted HTML appeared in "Result" on the right

Where to look on screen

01
Error band

Shows the line and column of the error and what is wrong. How to fix each kind of error is covered in "Common errors and how to fix them" below.

The error band above the input box outlined in red

STEP 3

Choose a format

Under "Format" at the top, choose an indent width or Minify. Indented code suits people reading it. Minify suits files you publish, because it makes them lighter.

Format and the result box outlined in red

Checkpoints

  • The shape of the result suits where you will use it

Where to look on screen

01
Format

Choose Indent space 2, Indent space 4, Indent tab, or Minify.

The Format menu outlined in red
02
Minify

Removes the spaces, line breaks, and comments added for reading, and puts everything on one line.

The minified result box outlined in red

STEP 4

Copy or save the result

Check "Result" on the right, then press "Copy" or use "Save" to make a file. Unclosed tags have been closed for you, so this is also where you check that they close where you intended.

The result box outlined in red

Checkpoints

  • The result is not cut off
  • Tags close where you intended

Where to look on screen

01
Copy and save

"Copy" copies the formatted HTML, and "Save" saves it as formatted.html.

"Copy" and "Save" in the result box outlined in red

Common errors and how to fix them

We entered common mistakes and checked what the band says for each.

What the band says and how to fix it
MistakeHTML enteredWhat the band saysHow to fix it
Missing closing " in an attribute value<div class="card>Hello</div>Line 1, column 29: Could not read to the end. Check for a missing " around an attribute value or a missing > of a tagAdd " after card
Closing tag does not match the opening tag<ul><li>One</li></ol>Line 1, column 17: There is a closing tag </ol> without a matching opening tagChange </ol> to </ul>
Closing tag with no opening tag<p>Hello</p></div>Line 1, column 13: There is a closing tag </div> without a matching opening tagDelete </div>, or add <div> before it
Missing < of an opening tagp>Hello</p>Line 1, column 8: There is a closing tag </p> without a matching opening tagAdd < at the start
Missing > of an opening tag<p class="a"Hello</p>Line 1, column 1: Something here cannot be readAdd > after "a"

If you forget the < of an opening tag, it is not read as an opening tag, so the error shows up as a closing tag error. If you cannot find a mistake where the band points, check the lines before it too.

How does the format change the character count?

We compared using the 135-character HTML that "Insert sample" puts in (written with Indent space 4).

Characters by format
FormatCharacters
Indent space 2119
Indent space 4135
Indent tab111
Minify96

Minifying took 135 characters down to 96, about 29% fewer. The more indents and line breaks your HTML has, the more minifying removes.

What does formatting fix for you?

InputFormatted resultWhat changed
<div><p>Hello</div><div><p>Hello</p></div>Closes the open p
<div><div></div>Closes the open div
<br><img src="a.png"><br /><img src="a.png" />Writes elements with no closing tag using />

What does minifying remove, and what does it keep?

ItemAfter minifying
CommentsRemoved
Line breaks and spaces between block elementsRemoved
The space between inline elements, as in <b>a</b> <i>b</i>One space stays (because it shows on the page)
Spaces inside pre and textareaKept as they are
Contents of style and scriptKept as they are

The contents of style and script do not get shorter. You can minify CSS with the CSS Formatter.

Notes

Notes

Important points are grouped with reasons so you can make decisions before using the tool.

Unclosed tags

Unclosed tags are closed for you, without an error

Even with no error band, check in the result that they close where you intended.

CSS and JavaScript

The contents of <style> and <script> are formatted too

Formatting tidies their contents as well. Minifying leaves their contents as they are.

Comments

Minifying removes comments

Keep any notes you want to keep in your original file.

FAQ

Questions about HTML Formatter

Questions that make decisions easier before use are summarized first.

Can I format just part of an HTML page?

Yes. It does not have to be a whole page. You can format any part of HTML you paste.

How is the location of an error shown?

Above the input box, the location and the reason appear, for example "Line 3, column 1: There is a closing tag </ol> without a matching opening tag". That line is also marked.

What happens to unclosed tags?

They do not cause an error. They are closed for you and formatted. Check in the result that they close where you intended.

Are the contents of <style> and <script> tidied too?

Formatting tidies their contents too. Minifying leaves their contents as they are. To minify CSS, use the CSS Formatter.

Is the HTML I enter sent anywhere?

No. Formatting happens in your browser. What you enter stays only in the browser on this device, so you can pick up where you left off when you open the page again.

Next guides

Related guides

Related guides are listed next so you can continue without getting lost.