HTML Formatter & Minifier
Format re-indents markup with the html_beautify function from js-beautify. Minify is a separate set of regular expressions that strips comments and whitespace between tags.
0 characters
Original
0 chars
Output
0 chars
Change
-
Related Developer Tools
Runs in your browser: your files and text are not uploaded. Free, no account needed.
Last updated: · Reviewed by the QuickTooly Team
How formatting and minifying work
Format: js-beautify Settings Used Here
The Format button calls html_beautify with these options:
indent_size/indent_with_tabs. Set by the Indent size menu. The default is 2 spaces.wrap_line_length: 0. Long lines are never wrapped, so a long paragraph stays on one line.preserve_newlines: false. Blank lines in your input are removed.
Everything else uses js-beautify defaults. Inline elements such as <b>, <a> and <span> stay on the same line as their text, and the content of <pre> and <textarea> keeps its original whitespace. The code inside <script> and <style> is re-indented too, using js-beautify's JavaScript and CSS formatters.
Worked example
With the default 2-space indent, this input:
<div><p>Hi <b>there</b></p><pre> keep
this</pre></div>becomes:
<div>
<p>Hi <b>there</b></p>
<pre> keep
this</pre>
</div>Minify: What the Regex Minifier Removes
- Comments, when "Strip comments when minifying" is on (the default). Comments that start with
<!--[ifare kept, because Outlook and old Internet Explorer read them. - Whitespace before and after block-level tags such as
<div>,<p>,<li>and<table>. Next to other tags, such as<b>or<a>, it becomes one space so words stay apart. - Runs of spaces, tabs and newlines inside text, which become one space.
Blocks of <pre>, <textarea>, <script> and <style> are set aside before this and put back afterwards. The minifier does not parse HTML, rename anything or shorten attributes.
Where HTML Minification Can Change the Page
- Elements restyled with CSS. The minifier decides by tag name, not by your stylesheet. A
<div>or<li>set todisplay: inlineloses the space next to it, so check text beside such elements. - CSS and JavaScript. Code inside
<style>and<script>is copied as is. Use the CSS and JavaScript minifiers for that code.
HTML Formatter Questions
Why did Format change the indentation inside my <script> block?
js-beautify formats embedded JavaScript and CSS with its own JS and CSS beautifiers, using the same indent size. Only <pre> and <textarea> content keeps its original whitespace.
Why are my blank lines gone after formatting?
The formatter runs with preserve_newlines set to false, so every blank line between elements is dropped. Add blank lines back by hand if you use them to group sections.
Does the minifier remove optional closing tags or attribute quotes?
No. It only removes comments and whitespace. Tags, attributes and quotes are left as they are.
Next Steps for Your Markup
- CSS Formatter: format or minify the stylesheet that this minifier leaves untouched.
- JavaScript Formatter: minify inline or external scripts with Terser.
- HTML Entities Encoder: escape characters such as < and & before pasting text into markup.