JavaScript Document embeds Property

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

Document.embeds is a read-only instance property that returns a live HTMLCollection of every <embed> element in the document. Learn how to count, loop, read src, compare plugins and querySelectorAll, and use five examples with try-it labs.

01

Kind

Read-only property

02

Returns

HTMLCollection

03

Matches

<embed> only

04

Live

Updates with DOM

05

Alias

document.plugins

06

Status

Baseline widely

Introduction

The HTML <embed> element inserts external content into a page—historically plugin formats, today often PDFs or other browser-handled resources. When a script needs every embed on the page, document.embeds gives a ready-made collection.

MDN: the embeds read-only property returns a list of the embedded <embed> elements within the current document. The HTML standard roots that collection at the document and filters only embed elements.

💡
Not every “embedded” tag

iframe, object, video, and audio are separate elements. They do not appear in document.embeds. Query those tags explicitly when needed.

Related Document tutorials: domain, applets, Document constructor.

Understanding Document.embeds

A read-only instance property on Document. Its value is a live HTMLCollection of every <embed> in the document tree.

  • ValueHTMLCollection of embed elements (MDN).
  • Read-only — you do not assign a new collection to document.embeds.
  • Live collection — reflects DOM changes when embeds are added or removed.
  • Indexed accessdocument.embeds[i] or item(i).
  • Named access — embeds with a name / id may be reachable via namedItem.
  • Same as pluginsdocument.plugins returns the same collection in modern HTML.

📝 Syntax

JavaScript
document.embeds

Value

An HTMLCollection of <embed> elements in the document.

Common patterns

JavaScript
const count = document.embeds.length;
const first = document.embeds[0];
const byName = document.embeds.namedItem("reportPdf");

for (const el of document.embeds) {
  console.log(el.src);
}

CSS-selector alternative

JavaScript
const embeds = document.querySelectorAll("embed");
// Static NodeList — does not auto-update when you add/remove embeds

📄 Quick look at <embed>

An embed points at a resource with src and often a type MIME hint. Dimensions use width / height.

JavaScript
<embed
  id="reportPdf"
  name="reportPdf"
  src="/files/report.pdf"
  type="application/pdf"
  width="600"
  height="400">
⚠️
Prefer modern media elements when they fit

For video/audio use <video> / <audio>. For nested browsing contexts use <iframe>. Keep <embed> for cases where that element is the right fit (for example some PDF viewers).

⚡ Quick Reference

GoalCode / note
All embedsdocument.embeds
Countdocument.embeds.length
First embeddocument.embeds[0]
Read sourcedocument.embeds[0].src
Same collectiondocument.plugins
Static NodeListdocument.querySelectorAll("embed")
MDN statusBaseline Widely available

🔍 At a Glance

Four facts about document.embeds.

Type
HTMLCollection

Read-only, live

Contains
embed

Only that tag

Alias
plugins

Same list

Status
baseline

Standard API

📋 What appears in document.embeds?

MarkupIn document.embeds?How to select instead
<embed src="a.pdf">Yesdocument.embeds or querySelectorAll("embed")
<iframe src="page.html">NoquerySelectorAll("iframe")
<object data="a.pdf">NoquerySelectorAll("object")
<video src="clip.mp4">NoquerySelectorAll("video")
<img src="pic.png">Nodocument.images / querySelectorAll("img")

Examples Gallery

Examples follow MDN Document: embeds. Use View Output or Try It Yourself for each case.

📚 Getting Started

Count embeds and read each resource URL.

Example 1 — Check document.embeds.length

Count how many <embed> elements exist on the page.

JavaScript
const count = document.embeds.length;
console.log("embed count:", count);

if (count === 0) {
  console.log("No <embed> elements on this page");
}
Try It Yourself

How It Works

length only counts <embed> tags—not iframes or objects.

Example 2 — Loop and List Each src

Walk the live collection and log each embed’s source.

JavaScript
for (const el of document.embeds) {
  console.log(el.tagName, el.src || "(no src)");
}

// Classic index loop also works:
for (let i = 0; i < document.embeds.length; i++) {
  console.log(i, document.embeds[i].src);
}
Try It Yourself

How It Works

HTMLCollection is iterable in modern browsers; index access works everywhere.

📈 Named Access, Live Updates & plugins

Look up by name, prove the collection is live, and compare aliases.

Example 3 — Access by Name with namedItem

If an embed has a matching name or id, look it up by string.

JavaScript
const report = document.embeds.namedItem("reportPdf");
if (report) {
  console.log("Found:", report.src);
} else {
  console.log("No embed named reportPdf");
}
Try It Yourself

How It Works

Prefer clear id attributes and getElementById when you need one specific node.

Example 4 — Live Collection Updates Automatically

Adding an <embed> increases document.embeds.length without re-querying.

JavaScript
const before = document.embeds.length;

const el = document.createElement("embed");
el.src = "https://example.com/demo.pdf";
el.type = "application/pdf";
document.body.appendChild(el);

const after = document.embeds.length;
console.log("before:", before, "after:", after);
// after === before + 1
Try It Yourself

How It Works

A static querySelectorAll snapshot would not grow unless you call it again.

Example 5 — document.plugins Is the Same Collection

Compare aliases and a static NodeList alternative.

JavaScript
console.log(
  "same object?",
  document.embeds === document.plugins
); // typically true

console.log("embeds:", document.embeds.length);
console.log("plugins:", document.plugins.length);

const staticList = document.querySelectorAll("embed");
console.log("querySelectorAll:", staticList.length);
Try It Yourself

How It Works

Use embeds (or plugins) for a live list; use querySelectorAll when you need CSS filtering or a frozen snapshot.

🚀 Common Use Cases

  • Inventory embeds — count or list every <embed> for debugging.
  • Audit sources — log each src before shipping a page.
  • Feature detection style checks — skip PDF UI when length === 0.
  • Legacy scripts — understand document.plugins referring to embeds.
  • Teaching live collections — show how length updates after DOM inserts.
  • Not for iframes — query iframe / object separately.

🧠 How document.embeds Works

1

Document hosts <embed> tags

Authors place one or more embed elements in the HTML tree.

Markup
2

Browser builds a filtered collection

HTML: an HTMLCollection rooted at the Document matching only embed elements.

Filter
3

You read length / index / namedItem

Scripts inspect or iterate the live list without writing a manual tree walk.

Access
4

DOM changes stay in sync

Add or remove embeds and the same collection object reflects the new set.

📝 Notes

  • MDN: Baseline Widely available (since June 2018) — no Deprecated / Experimental / Non-standard banner.
  • Value is an HTMLCollection of <embed> elements only.
  • document.plugins returns the same collection in modern HTML.
  • Live vs static: prefer querySelectorAll when you need a frozen snapshot or CSS filters.
  • Related: domain, applets, Document constructor.

Browser Support

Document.embeds 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.embeds

Read-only live HTMLCollection of every <embed> element in the document.

Widely Available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Supported in legacy IE
Full support
Document.embeds Baseline support

Bottom line: Use document.embeds to list every embed on a page. Remember it excludes iframe/object/video — and that document.plugins points at the same collection.

Conclusion

Document.embeds is the standard, live list of every <embed> in a document. Use it to count, inspect src, and keep scripts in sync with DOM changes—and remember that iframes and objects live in other queries.

Continue with featurePolicy, domain, applets, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use document.embeds for a live list of all embeds
  • Check length before indexing [0]
  • Prefer video / audio / iframe when they fit better
  • Use querySelectorAll for filtered selectors
  • Treat plugins and embeds as the same list today

❌ Don’t

  • Expect iframes or objects inside document.embeds
  • Assume a missing src still loads content
  • Confuse live HTMLCollection with static NodeList
  • Assign to document.embeds (it is read-only)
  • Rely on old NPAPI plugin APIs—those are gone

Key Takeaways

Knowledge Unlocked

Five things to remember about document.embeds

Live HTMLCollection of every <embed> — Baseline and ready to use.

5
Core concepts
02

Status

baseline

Standard
📦03

Matches

<embed>

Only
🔄04

Live

auto-updates

DOM
🔗05

Alias

plugins

Same list

❓ Frequently Asked Questions

A read-only HTMLCollection of every <embed> element in the current document. MDN describes it as the list of embedded elements within the document.
No. MDN marks Document.embeds as Baseline Widely available (since June 2018). It is a standard Document collection property.
No. The HTML standard filters only embed elements. Use document.querySelectorAll("iframe") or "object" for those other embedding tags.
Yes in modern HTML: document.plugins returns the same HTMLCollection as document.embeds (the embed elements in the document).
Yes. HTMLCollection is live — if you add or remove an <embed>, document.embeds.length and indexed access update automatically.
Both work. document.embeds is a convenient live collection of all embeds. querySelectorAll("embed") returns a static NodeList and supports richer CSS selectors when you need filters.
Did you know?

In the HTML living standard, document.plugins is defined to return the same HTMLCollection as document.embeds. The “plugins” name is historical; today it simply means the embed elements in the document.

Next: featurePolicy

Inspect Permissions Policy with the experimental FeaturePolicy API.

featurePolicy →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful