HTML object Tag

Beginner
7 min read
Updated: Oct 2026
4 examples
Live preview

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.

HTML Syntax

syntax.html
<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.

Attributes

The attributes you will use most often on <object>:

AttributeDescriptionNotes
dataURL of the resource to embedAt 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 pixelsPrefer CSS for responsive layouts
heightDisplay height in CSS pixelsPrefer CSS for responsive layouts
nameBrowsing-context / control nameUseful when targeting a nested context
formAssociates the object with a <form> by idForm-associated element
usemapObsolete — image-map hash referenceUse <img> with <map> instead
Plugin-era attrsObsolete: archive, border, classid, codebase, codetype, declare, standbyDo not use in new pages

Global Attributes

The <object> tag also supports the Global Attributes in HTML.

Live Preview

Switch between a successful embed and the fallback path (teaching simulation).

Always include fallback content inside <object> for when the resource cannot display.

Preview
PDF viewer (guide.pdf)

Resource loads — fallback hidden

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Embed a PDF

Use data + type and keep a download link as fallback.

HTML
<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>
Try It Yourself

How It Works

  1. Set data to the PDF URL.
  2. Set type="application/pdf" so the browser knows the format.
  3. Add width/height (or CSS) for the viewer box.
  4. 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.

HTML
<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>
Try It Yourself

How It Works

  1. Try to load the primary resource via data / type.
  2. If it fails, the browser shows the nested content.
  3. Use an <img> with alt so the fallback stays accessible.
  4. 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.

HTML
<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>
Try It Yourself

How It Works

  1. Pass width and height in CSS pixels.
  2. Match the resource aspect to avoid awkward letterboxing.
  3. Override with CSS (max-width: 100%) for small screens.
  4. 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.

HTML
<!-- 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>
Try It Yourself

How It Works

  1. Pick the dedicated tag for the media type when it exists.
  2. <video> gives controls, captions hooks, and clearer semantics.
  3. Reserve <object> for cases like PDF viewers or unusual MIME types.
  4. 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.

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.

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.

Default CSS Settings

Typical user-agent defaults (exact values vary by browser):

default.css
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

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.
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.
Optional param elements, then fallback content (transparent). If the resource fails, browsers show that fallback — often a link, image, or short message.
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).
No for authors. Those plugin-era attributes are obsolete. Use data and type, and optimize loading instead of standby.
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

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.

12 people found this page helpful