Just to add to this, HTML parsers will attempt to make sense of any random line noise you give it and turn it into a DOM. When I say something is "invalid" HTML, what I mean is that it's not allowed by the spec and will result in an error if you run it through a validator (which you should do!)
For example, try running the following document through the W3C's HTML validator[1]:
For example, try running the following document through the W3C's HTML validator[1]:
The HTML spec contains a list of all possible parse errors[2].[1] https://validator.w3.org/nu/#textarea
[2] https://html.spec.whatwg.org/multipage/parsing.html#parse-er...