Home HTML Tags <object> HTML object Tag Definition
Definition and Usage The <object> element embeds an external resource — treated as an image, a nested browsing context, or plugin content. A common modern use is showing a PDF in the browser’s built-in viewer.
Point to the file with data and declare its MIME type with type (at least one of those two is required). Put fallback HTML inside the element for when the resource cannot load. Prefer <img> , <video> , <audio> , or <iframe> when those fit better.
Baseline · Widely available. Not deprecated. Stable across browsers since about July 2015 (and much earlier in practice).
Obsolete attributes. Do not use archive, border, classid, codebase, codetype, declare, standby, or usemap on <object>. Use data/type, CSS for borders, and <img> for image maps.
Syntax
HTML Syntax <object data="resource-url" type="mime/type" width="…" height="…">
fallback content
</object> Both start and end tags are required. Optional <param> children may come first, then transparent fallback content.
Reference
Attributes The attributes you will use most often on <object>:
Attribute Description Notes dataURL of the resource to embed At least one of data or type required typeMIME type of the resource (e.g. application/pdf) Helps the browser choose how to handle it widthDisplay width in CSS pixels Prefer CSS for responsive layouts heightDisplay height in CSS pixels Prefer CSS for responsive layouts nameBrowsing-context / control name Useful when targeting a nested context formAssociates the object with a <form> by id Form-associated element usemapObsolete — image-map hash referenceUse <img> with <map> instead Plugin-era attrs Obsolete: archive, border, classid, codebase, codetype, declare, standbyDo not use in new pages
Try it
Live Preview Switch between a successful embed and the fallback path (teaching simulation).
Code
HTML Examples Short, copy-ready snippets. Use Try It Yourself for a live editor.
1. Embed a PDF 2. Fallback content 3. Width and height 4. Prefer native tags Example 1 — Embed a PDF Use data + type and keep a download link as fallback.
<object data="guide.pdf" type="application/pdf" width="480" height="320">
<p>PDF preview unavailable.
<a href="guide.pdf">Download the guide</a>.
</p>
</object> Embedded PDF: guide.pdf
Also keep a download link outside the object if the viewer loads but fails to render.
How It Works Set data to the PDF URL.Set type="application/pdf" so the browser knows the format.Add width/height (or CSS) for the viewer box.Put a download link inside as fallback if the embed fails.Example 2 — Image Fallback When Media Fails Children of <object> appear when the primary resource cannot display.
<object type="video/webm" data="flower.webm" width="320" height="180">
<img src="flower.jpg" width="320" height="180" alt="Yellow flowers in a field">
</object> flower.jpg (fallback image)
For new video work, prefer the native <video> element.
How It Works Try to load the primary resource via data / type.If it fails , the browser shows the nested content.Use an <img> with alt so the fallback stays accessible.If the image also fails , the alt text is what users get.Example 3 — Size the Embed Set intrinsic size with attributes; refine layout with CSS when needed.
<object
data="chart.svg"
type="image/svg+xml"
width="400"
height="240">
<p>Chart unavailable.
<a href="chart.svg">Open the SVG</a>.
</p>
</object> How It Works Pass width and height in CSS pixels.Match the resource aspect to avoid awkward letterboxing.Override with CSS (max-width: 100%) for small screens.Keep fallback text/links for unsupported or blocked files.Example 4 — When to Prefer video Instead object can point at video, but native <video> is clearer and more capable.
<!-- Prefer this for video -->
<video controls width="320" height="180">
<source src="clip.mp4" type="video/mp4">
Download <a href="clip.mp4">the video</a>.
</video>
<!-- object works, but lacks native controls API -->
<object data="clip.mp4" type="video/mp4" width="320" height="180">
<a href="clip.mp4">Download clip.mp4</a>
</object> <video controls> (preferred)
Use object when you need a generic embed (often PDF); use media elements for A/V.
How It Works Pick the dedicated tag for the media type when it exists.<video> gives controls , captions hooks, and clearer semantics.Reserve <object> for cases like PDF viewers or unusual MIME types.Always keep a download or text fallback either way. Edge Cases & Pitfalls Most object bugs are missing fallbacks, wrong MIME types, or using it where a media tag is better.
fallback Always provide children Empty <object> leaves users with nothing if the resource is blocked. Add a link or short message inside.
pdf Link outside too MDN notes a viewer may load yet fail to show the PDF. Keep a download link outside the element as well.
prefer Prefer dedicated elements Images → img. Video/audio → video/audio. Nested pages → iframe. Use object when those are a poor fit.
obsolete Skip plugin attributes classid, codebase, archive, standby, border, and usemap are obsolete for authors.
csp CSP uses object-src object has no loading="lazy"-style attribute. Sources are controlled by the page CSP object-src directive.
Compatibility
Browser Support The <object> element is core HTML embedded content in every browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
<object> Widely available since about July 2015 (and long before). PDF and MIME handling still vary by browser and user settings.
96% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer All
Supported object Widely supported
Bottom line: Safe to use. Always ship fallback content; prefer img/video/iframe when they are a better fit.
Remember
Key Takeaways Role: embed an external resource; PDF is a common case.
Attrs: set data and/or type; size with width/height or CSS.
Fallback: nested HTML shows when the resource cannot display.
Prefer: img/video/audio/iframe when they match the job.
One line: embed with data + type, always include fallback, and prefer dedicated media tags when possible.
UA style
Default CSS Settings Typical user-agent defaults (exact values vary by browser):
object {
display: inline;
}
/* Prefer explicit width/height (attrs or CSS).
Example responsive pattern:
object {
max-width: 100%;
height: auto;
} */ Size the box for your layout; do not rely on obsolete border attributes.
Frequently Asked Questions What is the HTML object tag for? The object element embeds an external resource — for example a PDF, image-like content, a nested browsing context, or a plugin-handled file — and can show fallback HTML if the resource cannot be displayed.
Which attributes are required? At least one of data (resource URL) or type (MIME type) must be set. In practice you usually set both: data for the URL and type for the content type.
What goes inside object? Optional param elements, then fallback content (transparent). If the resource fails, browsers show that fallback — often a link, image, or short message.
Should I use object for video or images? Prefer the dedicated elements: img for images, video for video, audio for audio, and iframe for nested pages. Use object mainly when those do not fit (common for PDF viewers).
Are classid, archive, and standby still valid? No for authors. Those plugin-era attributes are obsolete. Use data and type, and optimize loading instead of standby.
How is object different from embed? object supports richer fallback content and form association. embed is a void element with no fallback children. Prefer the more specific media tags when possible.
Next: ol Create ordered lists with the HTML ol element.
ol tutorial → About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
12 people found this page helpful
Helpful Share Copy link Suggestion