HTML Runner

How to Format HTML Code

Improve indentation without changing what the browser displays.

What you’ll learn

You’ll review formatting changes around inline text and preformatted content.

Choose an indentation convention

Use consistent indentation for nested blocks. Align closing tags with their matching opening tags when the markup allows line breaks.

Preserve meaningful whitespace

Keep existing spaces around inline elements. Treat pre and textarea as whitespace-sensitive and verify the contents remain intact.

Review the result

Format a copy, compare the diff, then preview both versions at the same width. If a visual detail changes, restore the original whitespace around it.

Try the code

<p>Read <strong>field notes</strong> today.</p>
<pre>name    score
Ada     12</pre>

Open the editor and paste this sample into the HTML tab.

Troubleshooting

An extra line break between inline elements can insert a visible space. If the formatter reports broken nesting, fix the markup first and then rerun the formatter.

Frequently asked questions

Can I minify the formatted file later?

Yes. Keep the readable source and minify a separate copy. Check the result because some whitespace is part of the content.

Related resources

Technical references