Skip to content

<object> - External Resource Element

Embedded Content HTML 4.0

The object element represents an external resource, which can be treated as an image, a nested browsing context, or a resource to be handled by a plugin. Its key advantage over <embed> is the ability to provide fallback content for progressive enhancement.

Result
<object data="resource.ext" type="mime/type">
Fallback content here
</object>

The <object> element requires both opening and closing tags. Content between the tags serves as fallback if the resource cannot be loaded or displayed.

AttributeDescriptionExample
dataURL of the resourcedata="document.pdf"
typeMIME type of the resourcetype="application/pdf"
widthWidth in pixels or percentagewidth="600" or width="100%"
heightHeight in pixelsheight="400"
nameName for form submission and scriptingname="pdf-viewer"
AttributeDescriptionExample
formAssociates object with a formform="myform"
typemustmatchEnforces type/data MIME type matchtypemustmatch
AttributeDescriptionStatus
classidWindows ActiveX class IDDeprecated
codebaseBase URL for relative pathsDeprecated
codetypeMIME type of codeDeprecated
declareDeclare without instantiatingDeprecated
standbyLoading messageDeprecated
archiveSpace-separated resource URLsDeprecated
borderBorder widthDeprecated - use CSS
align, hspace, vspacePositioningDeprecated - use CSS
Result

PDF URL Parameters:

  • #page=N - Open to page N
  • #zoom=150 - Set zoom percentage
  • #toolbar=0 - Hide toolbar
  • #navpanes=0 - Hide navigation
  • #view=FitH - Fit to width
  • #pagemode=bookmarks - Show bookmarks
Result
Result
Result
Result
Feature<object><iframe><embed>
Fallback content✅ Yes (nested)✅ Yes❌ No
Security sandbox❌ No✅ Yes❌ No
Permissions Policy❌ No✅ Yes❌ No
HTML documents✅ Yes✅ Yes✅ Yes
PDF support✅ Yes✅ Yes✅ Yes
SVG support✅ Yes✅ Yes✅ Yes
Form integration✅ Yes❌ No❌ No
Lazy loading❌ No✅ Yes❌ No
Browser supportExcellentExcellentGood

Best For:

  • Content with fallback needs
  • SVG with PNG/JPEG fallback
  • PDF with download option
  • Progressive enhancement
  • Legacy system compatibility

Example:

<object data="chart.svg" type="image/svg+xml">
<img src="chart.png" alt="Sales chart">
</object>
<object
data="infographic.svg"
type="image/svg+xml"
width="800"
height="600"
aria-label="2024 Sales Infographic">
<img src="infographic.png"
alt="Bar chart showing 25% sales increase in Q4 2024">
</object>
<object
data="report.pdf"
type="application/pdf"
width="100%"
height="600"
title="Annual Financial Report 2024">
<div>
<h2>Annual Financial Report 2024</h2>
<p>PDF viewer not available.</p>
<ul>
<li><a href="report.pdf" download>Download PDF (2.5 MB)</a></li>
<li><a href="report.html">View HTML version</a></li>
<li><a href="report.txt">Download text version</a></li>
</ul>
</div>
</object>
Result
Result
Result
Result
Result
Result
Result
Result

The <object> element can be associated with forms and participates in form submission:

Result
Result

CSP Directives:

  • object-src: Controls which sources can be used in <object>, <embed>, and <applet>
  • plugin-types: Restricts MIME types (deprecated)

Always specify the type attribute to prevent content type confusion:

<object
data="document.pdf"
type="application/pdf"
width="600"
height="400">
<p>Fallback content</p>
</object>
<object
data="image.svg"
type="image/svg+xml"
width="300"
height="200">
<img src="image.png" alt="Fallback">
</object>

The typemustmatch attribute forces the browser to verify that the type attribute matches the actual MIME type:

Result
FeatureChromeFirefoxSafariEdge
<object> element1+1+1+12+
PDF embedding1+19+5+12+
SVG embedding4+4+5+12+
typemustmatch❌ No50+❌ No❌ No
Flash plugin❌ Removed❌ Removed❌ Removed❌ Removed
Java plugin❌ Removed❌ Removed❌ Removed❌ Removed
Nested objects1+1+1+12+

Possible Causes:

  1. Incorrect MIME type
  2. Resource not found (404)
  3. Browser doesn’t support the content type
  4. CSP blocking the source
  5. CORS issues for cross-origin content

Solutions:

Result

Error: “Cannot read property ‘querySelector’ of null”

Cause: Trying to access cross-origin object content or accessing before load.

Solution:

Result