HTML Formatter
Make messy or minified HTML readable. Embedded <style> and <script> blocks are formatted too.
or drop a file here · .html, .htm, .txt · up to 20 MB
About the HTML Formatter
HTML copied from a page builder, an email template or a browser’s “view source” is often one enormous line, or indented by whoever touched it last. This formatter lays the markup out again with nested elements indented under their parents, and it also formats the CSS inside style blocks and the JavaScript inside script blocks.
It runs Prettier, a widely used open-source formatter, inside your browser.
When to use it
- You need to find one element in a minified template.
- A colleague sent a snippet and you want it laid out like the rest of your project.
Worked example
The sample behind Try an example is a page whose head, body and list sit flush against the left margin, with a cramped style rule and a one-line script. Keep 2 spaces and an 80 characters line width, then press Format HTML.
The head and body are now indented inside the html element, the meta tag ends with a slash in the usual Prettier style, and the style rule is spread over several lines with one property each. The paragraph keeps its bold word inline, and its run of three spaces after the full stop becomes one, which is how a browser would have shown it anyway.
How visible spacing is protected
In HTML, a space between two inline elements such as bold and italic text is visible on the page. The formatter follows the same whitespace rules as a browser’s default CSS, so it does not add or remove spaces that would change what readers see. As a result, some inline content may stay on one long line instead of being broken up; that is deliberate.
Limits
- Seriously broken markup cannot be formatted. You get the line and column of the problem; the HTML checker helps to find structural mistakes.
- For smaller files instead of tidier ones, use the HTML minifier. For stylesheets on their own, use the CSS formatter.
How to use HTML Formatter
- Paste HTML or open an .html file.
- Choose the indentation and line width.
- Select Format HTML, check the result, then copy or download it.
Privacy: how it works
Everything happens in your browser. Your text is not sent to any server.
Frequently asked questions
Will formatting change how my page looks?
It should not. The formatter treats spaces around inline elements such as <b> and <a> the way browsers do, so it avoids adding or removing visible spaces. Check the result before you replace a live page.
Why did it refuse my HTML?
The formatter needs to understand the structure. Badly broken markup, such as a closing tag with no opening tag, is reported with its position. The HTML validator can help you find such problems.
Which engine does it use?
Prettier, a widely used open-source code formatter, running entirely in your browser.