object
The HTML <object> element embeds an external resource and can contain fallback content for browsers or users that cannot use it.
What you will learn
- How to embed external data with
object - How child content works as a fallback
- How to choose between
embed,iframe, and a specific media element
Basic example with a fallback
<object data="guide.pdf" type="application/pdf">
<p>This browser cannot display the PDF.
<a href="guide.pdf">Download the guide</a>.
</p>
</object>
The data attribute identifies the resource and type describes its media type. The child paragraph is available as fallback content when the resource cannot be rendered.
Choose a more specific element first
- Image
- Use
imgwith meaningfulalttext. - Audio or video
- Use
audioorvideowith controls and a suitable fallback. - Another web page
- Use
iframeonly when embedding another browsing context is really intended. - General external data
- Use
objectwhen its fallback behavior and resource type fit the content.
Fallback is part of the experience
Write fallback content that lets the user continue: offer a download link, a text alternative, or an explanation of what the embedded resource contains. Do not leave an empty box with no next step.
Security and trust
An embedded resource comes from a trust boundary that should be considered. Check the URL, type, permissions, privacy impact, and performance. Do not treat object as a security sandbox for untrusted content.
Common mistakes
- Putting fallback text outside the
objectwhen it should be its child. - Using it for every image or video instead of the semantic element designed for that media.
- Providing fallback text that does not explain how to access the resource.
- Embedding third-party content without checking trust and privacy implications.