HTML formatter
Format HTML in your browser: nothing is uploaded, there is no limit on the size, and minified, generated or messy markup becomes neatly indented code. The content and attributes stay exactly as they were.
How it works
-
Paste your code
Paste the code in the left box or open a file. No code to hand? Click Example.
-
Instant result
The result appears as you type. If there is an error, you see the line and character.
-
Copy or download
Copy the result with one click or save it as a file for your editor or project.
What does it do?
Every block element (<div>, <p>, <ul>, <li> …) goes on its own line, indented by how deeply it is nested. Inline elements such as <a>, <b> and <span> stay inside the sentence, so text still reads naturally. The formatter only changes whitespace between tags; your content and attributes stay exactly as they were.
Options
- Indent with 2 spaces, 4 spaces or a tab.
- Keep blank lines preserves at most one empty line where you had them, so your own grouping stays visible.
- Keep inline elements on the same line can be switched off to put every tag on its own line.
Formatting uses js-beautify, which runs in your browser; nothing is uploaded. For XML, which has stricter rules, use the XML formatter.
Where messy HTML comes from
Template engines, page builders, e-mail tools and "view source" on a minified site all produce markup that is hard to read. Format it here to follow the nesting, find the unclosed element or compare two versions in a diff.
Whitespace in HTML can matter
Browsers collapse whitespace between inline elements into a single space, but not in <pre>, <textarea> and elements styled with white-space: pre. The formatter leaves the contents of <pre> and <textarea> alone. Between inline elements, adding line breaks can introduce a visible space where there was none (<b>a</b><i>b</i> is not the same as the two on separate lines), which is why keeping inline elements on one line is the default.
E-mail HTML
For HTML e-mails, which use tables and inline styles, format a copy to read it, but send the original. Mail clients can be sensitive to small differences in whitespace.
To check XML-based formats, such as an RSS feed or SVG, use the XML formatter. To tidy the styles and scripts that you copied out of a page, see the CSS beautifier and the JavaScript beautifier.
Frequently asked questions
Does formatting change how the page looks?
Normally not. Whitespace between block elements does not show. Between inline elements it can, which is why those are kept on one line by default.
Does it fix invalid HTML?
No. It only changes whitespace. Unclosed tags stay as they are, although the indentation often makes them easier to spot.
Are style and script blocks formatted too?
Yes, as CSS and JavaScript.
Is my HTML uploaded?
No. It is formatted in your browser and never sent anywhere.