What Got Eaten Was Content, Not Layout
The account starts from one 39B input. The sample has 6 lines: a div wrapping a pre block, two leading spaces on L1, a blank line in the middle, two trailing spaces on L2. Beautify turns the output into 50B over 7 lines: the pre open tag stands on its own line, each content line gets 4 more spaces of leading indent, the blank line in the middle is deleted whole, and only the two trailing spaces on L2 survive. This is not a layout preference; it is content being changed.
Every figure below comes from rerunning the HTML Formatter page itself: the template script block is loaded verbatim into Node v24 (node:vm plus a minimal DOM stub), and the page's own beautifyHTML and minifyHTML are called directly; structure counts come from a self-written stub traversal, with no third-party parser library involved.
The Two-Way Byte Account for Four Protected Node Types
| Node | Input | Beautified output | Minified output | Blanks inside the block |
|---|---|---|---|---|
| pre | 39B | 50B | 37B, only tag gaps folded | blank line deleted, 4 spaces padded |
| textarea | 43B | 59B | byte-identical to input | rearranged |
| script | 51B | 66B | byte-identical to input | rearranged |
| style | 50B | 69B | byte-identical to input | rearranged |
Three paired samples on the minify side come back unchanged, and the pre 39B only folds to 37B with its inner blank line intact; on the beautify side all four types come back with internal whitespace rearranged. The on-site entry text says all whitespace and newlines are removed, which fails in the minify direction for these types, and the automatic-indent claim never warns that indents get padded inside the block too.
The 70B Script Sample: the String Value Really Changed
The minimal construction is 70B: inside a script, first a template string var s = `A\n\nB`, then a multi-line block comment /* head\n\nfoot */, and on the last line var n = 1. The beautified output is 96B, and the value inside the backticks goes from "A\n\nB" to "A\n B": the blank line is deleted, and the continuation line is stuffed with 4 spaces of leading indent; the block comment likewise turns into "/* head\n foot */". The page adds indentation line by line and never recognizes JS string boundaries.
Output Shape Inventory
- void tags: the 27B input holding <br> and <hr class=x> beautifies to 35B, each alone on one line;
- self-closing form: 25B in, 41B out, <div/> kept verbatim, indent does not rise, unlike browser nesting semantics;
- empty paired tag: <span></span> splits from 13B into 15B across two lines; a custom element gives 34B from 29B, normal;
- unclosed custom element: 28B in, 57B out, the trailing </div> is pushed to level 2, later lines deepen, no error raised;
- angle brackets inside attributes: <img alt="a>b" title="c<d"> goes from 27B to 28B, the whole tag closing on one line;
- attribute order: the input order b, a, c is output verbatim, with no sorting done.
Nested Comments Truncate at the First -->
A multi-line comment keeps indentation only on the first line, the second starts flush left; an empty comment turns 18B into 24B and stays. The nested construction is the one to watch: <!-- a <!-- b --> c --> written as 34B in, 41B out: the parse truncates at the first -->, and the tail " c -->" leaks out as a standalone text line. With keep-comments off: 24B beautifies to 13B, minify yields <div></div> at 12B, the comment is deleted in full, but the leaked c --> text stays in the output, giving <div> c --></div>.
Three Indent Tiers: 20 Indent Slots Settle the Whole Bill
A single-line section wrapping a ul with two li plus one p, 56B in; all three tiers beautify to 14 lines: the 2-space tier 109B, the 4-space tier 149B, the Tab tier 89B. The output holds 20 indent slots in total, so the 4-space tier weighs 40B more than the 2-space tier and the Tab tier 20B less. All three tiers minify byte-identically at 56B, exactly equal to the input.
Attribute wrapping was probed too: a div built with 12 data attributes, 162B on one line, the open tag 155 characters wide; the beautified output is 167B over 4 lines with the longest line still 155. Each open tag keeps one whole line, the page code carries no wrapping logic at all, so the measured reading is never-wrap, with no attribute-count or column-width threshold.
The Three Structure Ledgers Miss This Damage
After beautifying, how do you confirm the structure did not change? A self-written stub traversal keeps three ledgers: element count, text node count, visible text length. A 65B sample beautifies to 93B, and {el:4, tn:3, vis:10} is identical before and after. The blind spot lives inside the protected nodes: once pre loses its blank line, vis still reads 5 characters and the structure ledger does not stir. What actually changes is whitespace inside keep-class nodes; ordinary element text is only trimmed at both ends, and the pair with a single space between loses one slot per side. Dump the counts into the JSON Viewer to spread them out, easier than counting plain text by eye.
The roundtrip applies minify(beautify(x)) to four new samples: R1, the pre sample, takes 39B, beautifies to 67B, then compresses back to 55B, while direct minify still returns 39B, a 16B gap; R2, the CJK list, goes 33B then 57B then 37B, 4B over; R3, a titled block with a comment, runs 32B then 40B then 35B, 3B over; R4, the textarea sample, walks 54B then 82B then 70B, 16B over. None equals the original character for character, nor the direct minify; two residue sources: re-glued spaces around standalone text lines, and indents padded inside protected blocks.
Boundary Inputs and the Stats Bar
An empty string outputs empty and the stats bar clears with no text, in 0.005ms; pure whitespace of 5 characters behaves like the empty string, 0.002ms. The comment-only input <!-- only --> of 13 characters beautifies to 14 characters, and the stats bar shows original 13 characters, result 14 characters, change +7.7% in red; minify with comments kept is still 13 characters, red "+0%", even 0 walks the red branch; minify with comments dropped shows 0 characters as "-100.0%" in green. The large document of 205019B equals 170851 characters, beautifies in 44.0ms into 298983B across 25629 lines, +55% on the character basis; minify takes 1.5ms and returns the input byte for byte. The formatting-error message never fired for any input above. The encode and decode side of the ledger was measured on the HTML entity encode and decode page, and this article does not touch it.
Three Common Questions
Q: After beautifying, can minifying return to the original?
It cannot. R1 through R4 end 16B, 4B, 3B and 16B above their originals; the gap is re-glued text-line spaces plus indents padded into protected blocks.
Q: If the structure ledgers do not move, is the content safe?
No. The counters el, tn and vis only cover ordinary nodes; after the pre blank line is deleted whole, vis stays at 5 characters without stirring. Whether the content inside a block survived has to be checked against the before-and-after byte account.
Q: Which library was used to measure this set?
No library. The template script block goes whole into node:vm with a minimal DOM stub, running the page's own two functions, and the structure traversal is self-written too; the page itself only calls UU.toast and UU.copy from the on-site shared script and references no external parser library.