About HTML Formatter
Paste markup copied from a browser, a CMS or a template and get it back with every element on a sensible line and nested one level deeper than its parent. The CSS in <style> blocks and the JavaScript in <script> blocks is formatted too.
Pick two spaces, four spaces or tabs, a line width of 80, 100 or 120 characters, and whether a tag that is too long for the line wraps its attributes as needed or puts each one on its own line. Switch to Minify for the opposite job. Formatting uses Prettier, in this tab.
How it works
- Your HTML is parsed with Prettier’s HTML parser, which follows the same rules for implied and optional tags as browsers do, and printed back with the indentation and line width you chose.
- Inline elements such as links and emphasis stay on the line of the text around them, so formatting does not add visible spaces to your page; text inside <pre> and <textarea> is kept as it was.
- In Minify mode a separate pass removes comments and the whitespace that cannot show on the page, and can also minify inline CSS with csso and inline JavaScript with Terser.
- The work runs in a background worker, so a large page never freezes the tab.
Questions
Why do some lines end with an odd-looking > at the start of the next line?
That is how Prettier avoids adding whitespace between inline elements, where a new line would show as a space on the page. It looks unusual, but the page renders exactly as before.
What happens if my HTML has a mistake in it?
A closing tag that does not match anything open stops the formatter, and the message gives the line and column. Most other slips, such as a missing optional closing tag, are handled the way a browser would handle them.
Can it format templates such as Handlebars, Jinja or JSX?
Only where the template is also valid HTML. Template tags inside text are usually kept, but tags inside attributes or around elements may be rejected or moved.
Is my markup sent anywhere?
No. The formatter is loaded into this page the first time you use it and runs on your device. Documents up to 2 MB are accepted.
Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.