Skip to content

HTML Formatter

Beautify and indent HTML code.

Runs in your browser · free · no sign-up

Input
Result

About the HTML Formatter

Make messy or minified HTML easy to read. Nested tags are indented, long lines are wrapped and the CSS and JavaScript inside style and script tags are formatted as well.

HTML from page builders, email templates, CMS exports and view-source is often a dense wall of tags with no indentation. Understanding the structure, finding a missing closing tag or editing a section becomes guesswork. This formatter re-indents HTML so every nested element is visibly inside its parent.

Choose an indent of 2 spaces, 4 spaces or a tab and a maximum line length for wrapping long lines, or set it to 0 to turn wrapping off. CSS inside <style> tags and JavaScript inside <script> tags are formatted too. Content in <pre> and <textarea> is left exactly as it is, because whitespace there is visible to users. Formatting is done with js-beautify, a well-established open-source library, and the result can be copied or downloaded.

How to use the HTML Formatter

  1. 1Paste your HTML.
  2. 2Choose indent size and line wrap length.
  3. 3Click Format and copy the result.

Key features

  • Indent with 2 spaces, 4 spaces or tab.
  • Optional line wrapping.
  • Formats embedded CSS and JavaScript.
  • Preserves <pre> and <textarea> content.
  • Copy or download as .html.

Practical uses

  • Reading the source of a page builder or email template.
  • Tidying HTML before committing it.
  • Finding unclosed or misplaced tags.
  • Teaching HTML structure.
  • Inspecting HTML generated by a JavaScript framework.

Example

A one-line <ul><li><a href="/">Home</a></li><li><a href="/blog">Blog</a></li></ul> becomes a list with each <li> on its own line, indented under <ul>, making the structure clear at a glance.

Tips and common mistakes

  • Format before comparing two HTML versions so differences are easier to see.
  • If indentation looks wrong, look for a missing closing tag just above the problem.
  • Minify again before deploying if file size matters.
  • Set the wrap length to 0 when formatting HTML for email templates, where unexpected line breaks inside attributes can cause problems.

Limitations

  • Broken HTML is not repaired.
  • Template syntax such as PHP or Handlebars may be formatted imperfectly.

Privacy

HTML is formatted locally.

Frequently asked questions

Will it fix broken HTML?

It formats what is there but does not repair missing tags.

Does it change content inside <pre>?

No. Content in pre and textarea is kept exactly.

Which engine is used?

js-beautify, a widely used open-source formatter.

Can it format a whole web page?

Yes. Paste the full document, from <!doctype html> to </html>, and it is formatted as one file.

Can it format PHP templates?

It formats the HTML parts. PHP tags are kept but may not be indented ideally.

Does it change attribute order or quotes?

No. Attributes stay as written; only indentation and line breaks between tags change.

Related tools

HTML Entity EncoderEscape or unescape HTML special characters.
HTML MinifierShrink HTML by removing spaces and comments.
HTML to MarkdownConvert HTML into clean Markdown.
YouTube Embed Code GeneratorNewResponsive YouTube iframe code with start time and options.