<object>
Defines an embedded object or external resource
Definition and Usage
The <object> element establishes a container for an external resource, such as a web page, a picture, a media player, or a plug-in application.
The <object> element can be used to embed various types of content:
- Images, videos, and audio files
- PDF documents
- Other HTML pages
- Flash files (deprecated)
- Java applets (deprecated)
- SVG graphics
<param> tag to define parameters for plugins embedded with the <object> element.
<img> tag. For video and audio, use <video> and <audio> tags.
Browser Support
The <object> tag is supported in all major browsers:
Attributes
| Attribute | Value | Description |
|---|---|---|
| data | URL | Specifies the URL of the resource to be used by the object |
| type | media_type | Specifies the MIME type of the resource specified in the data attribute |
| name | name | Specifies a name for the object |
| usemap | #mapname | Specifies the name of a client-side image map to be used with the object |
| form | form_id | Specifies which form the object belongs to |
| width | pixels | Specifies the width of the object |
| height | pixels | Specifies the height of the object |
| typemustmatch | typemustmatch | Specifies that the type attribute and the actual content type of the resource must match |
Examples
Embed a PDF Document
Embed a PDF file with fallback content:
Example
<object data="document.pdf" type="application/pdf" width="100%" height="600">
<p>Your browser doesn't support PDFs.
<a href="document.pdf">Download the PDF</a> instead.</p>
</object>
Embed an Image with Fallback
Display an image with fallback text:
Example
<object data="image.jpg" type="image/jpeg" width="500" height="300">
<p>Image cannot be displayed. Please check your connection.</p>
</object>
Embed a YouTube Video
Embed a YouTube video using object tag:
Example
<object data="https://www.youtube.com/embed/dQw4w9WgXcQ" width="560" height="315">
<p>Your browser doesn't support embedded videos.</p>
</object>
Embed SVG Graphics
Display an SVG file:
Example
<object data="graphic.svg" type="image/svg+xml" width="400" height="400">
<img src="graphic.png" alt="Fallback image">
</object>
Embed with Parameters
Use param elements to pass parameters:
Example
<object data="movie.swf" type="application/x-shockwave-flash" width="400" height="300">
<param name="autoplay" value="true">
<param name="loop" value="false">
<p>Flash is not supported in your browser.</p>
</object>
Embed Another HTML Page
Display another HTML page within the current page:
Example
<object data="snippet.html" width="100%" height="400">
<p>Error loading the HTML content.</p>
</object>
Fallback Content
The content placed between the opening and closing <object> tags is fallback content. This content is displayed only if the browser cannot load the specified resource:
Example
<object data="media.pdf" type="application/pdf">
<!-- Fallback content -->
<p>This browser does not support PDF viewing.</p>
<p><a href="media.pdf">Download the PDF</a> to view it.</p>
</object>
Common MIME Types
When using the type attribute, specify the correct MIME type:
application/pdf- PDF documentsimage/jpeg,image/png,image/gif- Imagesimage/svg+xml- SVG graphicsvideo/mp4,video/webm- Video filesaudio/mpeg,audio/ogg- Audio filestext/html- HTML documentsapplication/x-shockwave-flash- Flash (deprecated)
Object vs Embed vs Iframe
| Feature | <object> | <embed> | <iframe> |
|---|---|---|---|
| Fallback Content | Yes (nested content) | No | Yes (nested content) |
| Parameters | Yes (<param> tags) | Yes (attributes) | No |
| Closing Tag | Required | Not required | Required |
| Best For | PDFs, SVGs, legacy plugins | Simple multimedia embeds | Embedding web pages |
| HTML Standard | HTML 4 & HTML5 | HTML5 | HTML 4 & HTML5 |
Best Practices
- Always provide fallback content for browsers that cannot display the object
- Use the appropriate
typeattribute to specify the MIME type - Consider using
<iframe>for embedding videos (better support) - Use
<img>,<video>, or<audio>tags when possible for better semantics - Specify both
widthandheightattributes to prevent layout shifts - Avoid using
<object>for Flash or Java applets (deprecated and unsupported) - Test your embedded content across different browsers and devices
- Provide download links as fallback for documents like PDFs
HTML Free Codes