Formatting one line of minified HTML, and the closing tags it never had
Take this line of minified HTML: a ul holding "<li>Tea<li>Coffee", then a closing </ul>, then a paragraph that says "Read the menu first." with "the menu" as a link, and then "<div>Open daily</div>". Everything is on one line. There is no </li> after Tea or Coffee, and no </p> after the paragraph. This is valid HTML. The standard lets you leave those closing tags out, and minifiers often do.
A browser reads it with a few rules. A new <li> closes the open <li> before it, so Tea and Coffee are two separate items. The </ul> closes the second item and the list. A <div> cannot sit inside a <p>, so when the browser meets <div>, it closes the paragraph first. The formatter uses the same rules. Its output has five lines for the list: <ul>, then <li>Tea</li> indented by two spaces, then <li>Coffee</li>, then </ul>. After that comes the paragraph on one line with a </p>, and then the div on its own line. The closing tags in the output are the ones the browser already assumed.
Look at the paragraph line: <p>Read <a href="/menu">the menu</a> first.</p>. The link stays on the same line as the words around it. That is deliberate. Between inline elements, a line break shows on the page as a space. If the formatter put the link on its own line, the browser would show a space where each line break is. Here that would be harmless, because there are spaces around the link already. In "un<b>believ</b>able" it would split the word in three. Keeping inline content together is the only way to be sure the page looks the same. When a paragraph is longer than 80 characters, its content goes on its own indented line inside the p, but it is never split across lines, except after a <br>.
Some content is never touched. A pre element shows every space and line break, so the formatter copies it exactly, even if its indentation does not match the lines around it. Text in a textarea is treated the same way. Script and style blocks are moved to the right depth as a whole, with their own lines kept as you wrote them.
The formatter has limits. It lays out HTML; it does not fix it. A closing tag with no opening tag is kept in place rather than dropped, so you can find it. It cannot see your CSS, so an element with white-space: pre set in a stylesheet may gain spaces. It does not reformat JavaScript or CSS line by line. And it does not keep the formatting quirks of your source, such as blank lines between sections. The goal is a layout you can read, not a copy of the original.