This behavior is documented in the HTML standard (chapter 6.2.4).
The standard defines “named elements” which are HTML elements that have either a name
or id
attribute set. (Note that the name
attribute is only defined on certain types of HTML elements.)
For each named element, the browser (environment) defines a corresponding global property.