HTML Formatter, Indent and Beautify HTML, Private
Indent messy or one-line HTML in your browser. Choose 2 spaces, 4 spaces or tabs. Only whitespace changes, and pre, textarea, script and style content is kept exactly. Nothing is uploaded.
0 characters, 0 bytes
0 characters, 0 bytes
About the HTML Formatter
The HTML Formatter takes HTML that is squeezed onto one line, copied from a page source or written without a consistent style, and indents it so the structure is easy to read. Paste your HTML into HTML and the formatted version appears next to it as you type. Choose 2 spaces, 4 spaces or Tab for the indent, then copy the result or press Download .html.
Your HTML never leaves your device. The formatting code runs in the page, so nothing is uploaded, logged or stored, and it is gone when you close the tab. The formatting code itself is only downloaded the first time you type something, so the page stays light until you use it.
How to use it
Steps
- Paste or type HTML into HTML.
- Pick an Indent. The default is two spaces.
- Read the note under the result, such as Formatted into 4 lines.
- Press Copy or Download .html to take the result with you.
Only whitespace changes
The formatter never adds, removes, renames or reorders anything except spaces and line breaks. If you remove every whitespace character from the input and from the output, the two strings are identical; the test suite checks this on a large set of documents, so a formatting bug cannot silently drop a tag or a word. Attribute values, entities such as & and , and the case of tag names are kept exactly as you wrote them.
What stays exactly as written
Some content is whitespace-sensitive, so the formatter copies it without touching it:
preblocks, where line breaks and spaces are the content.textarea, where the text is the field's default value.scriptandstyle, which hold code in another language.title, which holds plain text.
Text elsewhere has runs of spaces and line breaks collapsed to a single space, the same way a browser does when it draws the page. A non-breaking space ( or the character itself) is not collapsed.
Block and inline elements
Block elements such as div, ul, section and table each start on their own line, and their children are indented one level. Inline elements such as a, b, span and em stay with the text around them, so <p>Hello <b>world</b>!</p> is not broken into four lines that would add visible gaps. Void elements such as br, img and input do not add a level of indent.
Worked example
Input:
<ul><li>a</li><li>b</li></ul>
With two spaces the result is:
<ul>
<li>a</li>
<li>b</li>
</ul>
The note reads Formatted into 4 lines.
Broken markup is not rejected
HTML is forgiving, and so is this tool. Unclosed tags, a stray end tag or a lone < do not cause an error; the formatter keeps every character and indents what it can. It is a formatter, not a validator, so it will not tell you that your document is invalid. To shrink the result again, use the HTML Minifier, and for stylesheets use the CSS Minifier.
Frequently asked questions
Is my HTML uploaded?
No. The formatter runs in your browser, so the markup is not uploaded, logged or stored. Closing the tab clears it. The formatting code is downloaded the first time you type, and after that no network request is made with your HTML.
Can formatting change how my page looks?
It only changes whitespace, and it treats whitespace the way a browser does. Content in pre, textarea, script, style and title is copied exactly, text keeps a single space between words, and inline elements stay with their text, so the rendered page should look the same.
Why are some tags not on their own line?
Inline elements such as a, b, span and em stay on the same line as the text around them. Breaking them onto separate lines would add visible gaps between words, which would change how the page is displayed.
What happens with invalid or unfinished HTML?
Nothing is rejected. Unclosed tags, stray end tags and a lone less-than sign are kept as they are and indented as well as possible. The tool never drops or reorders content, but it does not validate your markup either.
Does it format the CSS and JavaScript inside my HTML?
No. Style and script content is copied exactly as written. To format code, use the Code Formatter, and to shrink a stylesheet use the CSS Minifier.