Imagine opening this page on a slow phone connection. The media should still be worth the wait and have a sensible fallback.
What You Need to Know
Object can display an external resource and include fallback content between its tags. If the resource cannot be shown, the browser can present the fallback instead.
In this example: embed a PDF with a fallback link.
Try the Example
Take a look at the example. We’ll explain the important lines right below it.
<object data="media/diagram.svg" type="image/svg+xml" width="320" height="240">
<img src="images/diagram.png" alt="Diagram of the water cycle">
</object>
Let’s Read the Code
- <object>: An object attempts to embed a resource and can contain fallback content.
- <img>: The img displays a picture; its alt is the text alternative.
- type: Type changes what sort of control or resource the browser uses.
- width: Width gives a preferred or intrinsic media width, depending on the element.
Read the named elements and attributes together. They explain how the browser connects this feature to the rest of the page.
What Happens in the Browser?
The paths shown here refer to files in your own example project. Put real images and recordings in those locations before expecting them to load.
Remember the boundary. Embedded content may be a separate document, sometimes provided by another company. Give it a readable title or alternative, and check what permissions and information its request may expose.
Your Turn
Try changing one file path or attribute. Notice whether the browser falls back to another source or shows missing content.
Common Beginner Mistakes
- Leaving out real media files or understandable text alternatives.
- Media and remote embeds can use significant bandwidth or reveal a visitor’s network information to another provider.
Key Takeaways
- Object can display an external resource and include fallback content between its tags.
- <object>: An object attempts to embed a resource and can contain fallback content.
- Test the behavior you expect rather than trusting how the snippet looks in your editor.