Read length again. Live collection increases by one.
Named access works immediately for the new form’s name.
Compatibility
Browser Support
Document.forms is marked Baseline Widely available on MDN (since June 2018). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Document.forms
Read-only live HTMLCollection of every form element in the document.
WidelyAvailable
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported in legacy IE
Full support
Document.formsBaseline support
Bottom line: Use document.forms to list and look up forms. Prefer document.forms.name over document["name"]. See the MDN Document.forms reference.
Frequently Asked Questions
A read-only HTMLCollection of every <form> element in the document. Each item is an HTMLFormElement. If there are no forms, length is zero (MDN).
No. MDN marks Document.forms as Baseline Widely available (since June 2018). It is a standard Document collection property.
Use document.forms.login or document.forms["login"] for a form with name="login". Prefer this over document["login"].
MDN warns that pattern is dangerous and discouraged — it can conflict with existing or future Document APIs. Always use document.forms for named forms.
Use the form's elements collection: document.forms[0].elements or loginForm.elements.email (MDN).
Yes. HTMLCollection updates when forms are added or removed from the document.