The HTML parser builds a document tree from tokens and may repair malformed nesting instead of rejecting the page.
HTML parsing: void elements and repaired markup
Use it for a real task
A receipt page should never depend on that repair. The image, line break, and input are void elements and have no closing tags or child content. Headings and paragraphs have clear starts and ends, so the intended DOM is easy to inspect. A browser may close a paragraph when a section begins, but another tool reading the source may expose the mistake differently.
<main>
<h1>Receipt R-47</h1>
<p>Review the receipt before export.<br>Keep the record ID visible.</p>
<img src="/media/receipt-mark.svg" alt="" width="36" height="36">
<label for="review-code">Review code</label>
<input id="review-code" name="review_code" type="text">
</main>What the markup guarantees
The image path needs an owned asset. An empty alt is justified here only if this mark adds no information beyond the nearby heading. Parsing rules do not make an invalid document a sound content model; inspect the DOM that the browser actually constructed.
Cost and limits
Parser repair may appear cheap, but debugging a DOM that differs from source costs time and can change CSS or scripting behavior. Keep tags explicit in authored examples and validate generated HTML.
Common Mistakes
- Do not add children to img or input.
- Do not depend on a browser silently closing misplaced paragraphs.
- Do not confuse source text with the final DOM tree.
