Document.links is a read-only instance property that returns a live HTMLCollection of every <a> and <area> element with an href attribute. Learn MDN’s loop example, how it differs from document.anchors, live collection behavior, and five examples with try-it labs.
01
Kind
Read-only
02
Returns
HTMLCollection
03
Matches
a / area + href
04
Live
Updates
05
Access
[0] / item()
06
Status
Baseline widely
Fundamentals
Introduction
Want every hyperlink on a page without writing a selector? document.links gives you a ready-made collection of all <a href="..."> and <area href="..."> elements.
MDN: the read-only property returns a collection of all <a> and <area> elements in a document with a value for the href attribute.
Document.links 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.links
Read-only live HTMLCollection of every a and area element with href.
UniversalWidely available
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.linksExcellent
Bottom line: Use document.links for quick access to all hyperlinks. Prefer querySelectorAll when you need filtered or scoped link queries.
Wrap Up
Conclusion
Document.links is a simple, live shortcut to every hyperlink on the page — both <a href> and <area href>. Use it to count, loop, and inspect link URLs, or reach for querySelectorAll when you need more specific queries.
Use document.links.length for a quick hyperlink count
Loop with for...of in modern code
Parse link.href with the URL API for host/path checks
Remember image-map <area> links are included
Use querySelectorAll when you need filtered subsets
❌ Don’t
Expect <a> without href to appear
Confuse document.links with deprecated document.anchors
Cache length across long loops if DOM may change mid-loop
Assume href in HTML equals the resolved link.href string
Skip accessibility checks on dynamically added links
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.links
All hyperlinks in one live collection.
5
Core concepts
🔗01
Returns
HTMLCollection
API
📄02
Items
a / area + href
MDN
🔄03
Live
Auto-updates
MDN
🔢04
Access
[0] / item()
Equivalent
🔍05
Loop
for...of
MDN
❓ Frequently Asked Questions
A read-only HTMLCollection of every a and area element in the document that has an href attribute — in other words, every hyperlink on the page.
No. MDN marks Document.links as Baseline Widely available (since June 2018). It is a standard, supported Document property.
Anchor elements (<a href="...">) and area elements inside image maps (<area href="...">). Elements without an href value are excluded.
document.links lists hyperlinks with href. document.anchors lists named anchor targets with a name attribute (<a name="...">) and is deprecated. One element can appear in both if it has name and href.
Yes. Use for...of, a classic for loop with length and index, or spread into an array. The collection is live — it updates when matching links are added or removed.
Use document.links for every hyperlink quickly. Use querySelectorAll when you need filtered links (for example a.external), scoped queries inside a container, or a static NodeList snapshot.
Did you know?
document.links and document.anchors sound similar but serve different jobs: links lists hyperlinks with href (still standard), while anchors lists named in-page targets with name (deprecated). A single <a name="x" href="#y"> can appear in both collections.