HTML Formatter
Format a template fragment without opening it as a live web page. This tool passes the source to the locally bundled Prettier HTML parser and writes the result into a text output. Script tags, event attributes and remote image URLs remain source text and are not executed or loaded by the formatter. The first formatting request loads the formatter library on this page only. Indentation can help expose nesting mistakes, but formatted markup is not automatically valid, accessible or safe to publish.
Your workspace
Runs locally in your browserResult
Your input is processed locally in your browser unless explicitly stated otherwise. Inputs are not saved by this tool.
How to use this tool
Paste HTML source, choose indentation, and format. Copy the formatted source; no rendered preview is created.
Example
Input
<div><h1>Hello</h1><p>World</p></div>Output
<div><h1>Hello</h1><p>World</p></div>What does this tool do?
HTML has void elements such as img and input that do not use closing tags, and some end tags may be optional. An HTML formatter therefore follows different rules from an XML pretty printer. Use the XML tool for XML documents rather than assuming the two syntaxes are interchangeable. Template-language directives outside ordinary HTML may not be accepted.
Common mistakes and limitations
The formatter uses strict whitespace sensitivity to avoid casually changing meaningful spaces around inline elements. That can leave some short fragments on one line. Embedded JavaScript and CSS formatting is disabled; those blocks are not evaluated or minified. This is not an HTML sanitizer: dangerous attributes remain in the returned text and must be reviewed before placing that text on another website.
Frequently asked questions
Will pasted script tags run?
No. Input and output are handled as text. This does not make the resulting HTML safe to execute elsewhere.
Related tools
XML Formatter
Pretty-print XML with basic validation and readable nested elements.
Open tool Developer ToolsCSS Minifier
Minify CSS with a local parser while preserving strings and important comments.
Open tool Developer ToolsJavaScript Minifier
Minify JavaScript locally with Terser without evaluating the supplied code.
Open tool