
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - Embed Multimedia
In the previous two chapters, we have used the <audio>
and <video>
elements to add music and videos into our web page. There are other alternative ways to add videos, sounds, images, or any other external content to the website by using HTML tags <embed>
and<object>
. These tags cause the browser itself to include controls for the multimedia automatically:
- HTML
<embed>
tag is used to embed external content such as images, videos, and web applications. It is often used for embedding content like Flash movies or audio/video players. - HTML
<object>
tag is used to embed various types of external resources, including images, videos, PDFs, and other web resources. It can render multiple types of files.
Syntax
Here is the syntax of embedding multimedia in the webpage:
Embed tag:<embed src = "url_of_resource">Object tag:
<object data="url_of_resource" type="typeOfResource">
Attributes of <embed> Tag
The following are the attributes used with the <embed>
tag:
Attribute | Description |
---|---|
width |
Width attribute is used describe width of the embedded file in pixels. |
height |
Height of the embedded file in pixels. |
title |
It is used to label the content. The title should describe the content. |
src |
URL of the file to be embedded. |
type |
It indicates the type of input like mp4 and mp3. |
Attributes of <object> Tag
The following are the attributes used with the <object>
tag:
Attributes | Description |
---|---|
data |
The location or path of the resource is passed into data attribute. |
type |
It indicates the type of resource. |
height |
It signifies the height of the resource display area. |
width |
It signifies the width of the resource display area. |
form |
Its value is the id of a form. The form attribute shows which object is associated with the form. |
name |
It specify a unique name for the object. |
usemap |
Specifies a URL of a client-side image map to be used with the object. |
Examples of HTML Multimedia Embedding
Here are a few examples that illustrate how to render multimedia content in a webpage using the <embed>
and <object>
tags:
- Embedding a Video Using <embed> Element
- Embedding an Audio Using <embed> Element
- Render a PDF Using <object> Element
- Render an HTML Document Inside Webpage
Embedding a Video Using <embed> Element
To embed an external video file inside the web page, we can pass the path of the video file into the src
attribute of the <embed>
element. The supported video formats are MP4, WebM, and Ogg. We dont need to use the controls attribute, as the <embed>
tag provides the controls automatically depending on the type of media. The controls attribute allows users to manage the video playback functions.
The following example demonstrates how to embed a video file using the embed element:
<!DOCTYPE html> <html> <head> <title>HTML embed Tag</title> </head> <body> <h1>Playing video using embed tag</h1> <embed src="/https/www.tutorialspoint.com/html/media/video/sampleTP.mp4" type="video/mp4" width="450" height="250"> </embed> </body> </html>
Embedding an Audio Using <embed> Element
To add a soundtrack to the webpage, we can pass the path of the audio file into the src
attribute by mentioning the type
of audio. The supported audio formats are ogg, mp3, and wav.
The following example demonstrates how to embed an audio file using the <embed>
element:
<!DOCTYPE html> <html> <head> <title>HTML embed Tag</title> </head> <body> <h1>Playing audio using embed tag</h1> <embed src = "/html/media/audio/sample_3sec_audio.mp3" type = "audio/mp3" width="450" height="250"> </embed> </body> </html>
Render a PDF Using <object> Element
HTML 4 introduces the <object>
element, which offers an all-purpose solution to generic object inclusion. The <object>
element allows HTML authors to specify everything required by an object for its presentation by a user agent.
We can embed a PDF document in an HTML document as follows:
<!DOCTYPE html> <html lang="en"> <head> <title>PDF Embed Example</title> </head> <body> <h1>Embedding a PDF Document</h1> <p>Here is an embedded PDF document:</p> <object data="html/pdf/index.pdf" type="application/pdf" width="300" height="200"> </object> </body> </html>
Render an HTML Document Inside Webpage
We can embed an HTML document in an HTML document itself as follows:
<!DOCTYPE html> <html lang="en"> <head> <title>HTML Embed Example</title> </head> <body> <h1>Embedding an HTML Document</h1> <p>Here is an embedded HTML document:</p> <object data="html/index.htm" type="text/html" width="500" height="400"> alt : <a href="html/index.htm"> test.htm </a> </object> </body> </html>
Comparison between <object> and <embed> Tags
Comparison between two similar tags will help to choose the right tag on the right place.
Feature | <object> | <embed> |
---|---|---|
HTML Tag | <object> | <embed> |
Usage | Embeds multimedia like audio, video, Java applets, ActiveX, PDF, and Flash. | Primarily used to embed multimedia content |
Attributes | Supports various attributes like data, type, width, and height. | Supports various attributes like src, type, width, and height. |
HTML5 | Supported | Supported |
Fallback Content | Can include fallback content within the tag | Cannot include fallback content within the tag |
The object tag supports fallback content, which means if a version of a browser does not support the object tag, then the content written inside the object tag is displayed instead of the object tag.