- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML Embed & Object
HTML Images and Media
HTML Embed & Object
Want to show a PDF inside your page? embed and object both do it. The difference is what happens when the browser cannot display the file: embed shows nothing, object lets you show a download link instead.
Both elements put an outside file into the page. Today that is almost always a PDF. Images, audio, video and other web pages have their own better tags: <img>, <audio>, <video> and <iframe>.
HTML <embed> Element
<embed> is a single tag with no closing tag and nothing inside it. You point it at a file and give it a size.
Syntax
html
<embed src="example.pdf" type="application/pdf" width="600" height="400">srcis the address of the file.typetells the browser what kind of file it is, such asapplication/pdf.widthandheightset the size of the box, in pixels.
HTML Embed Example
html
<embed src="https://ik.imagekit.io/html5andcss3/lesson-samples/sample.pdf" type="application/pdf" width="600" height="800">That shows the PDF in a box inside the page, using the browser's own PDF viewer.
HTML <embed> Attributes
| Attribute | What it does |
|---|---|
| src | The address of the file to show. |
| type | The kind of file (MIME type), like application/pdf. |
| width | Width of the box in pixels. |
| height | Height of the box in pixels. |
Older tutorials list autoplay, loop and hidden for embed. Those were never standard HTML; they were passed to browser plugins, which no longer exist.
HTML <object> Element
<object> does the same job, but it has a closing tag, and whatever you put between the tags is shown if the file cannot be displayed. That backup content is the reason to choose it.
HTML Object Syntax
html
<object data="example.pdf" type="application/pdf" width="600" height="400">
Your browser does not support embedded objects.
</object>datais the address of the file (note:data, notsrc).typeis the kind of file.widthandheightset the size.- The content inside is the fallback.
HTML Object Example
html
<object data="https://ik.imagekit.io/html5andcss3/lesson-samples/sample.pdf" type="application/pdf" width="600" height="800">
<p>It appears your browser does not support PDF viewing. <a href="https://ik.imagekit.io/html5andcss3/lesson-samples/sample.pdf">Download the PDF</a>.</p>
</object>If the browser can show PDFs, you see the document. If not, for example on many phones, the reader gets a "Download the PDF" link instead of an empty box.
HTML <object> Attributes
| Attribute | Description |
|---|---|
| data | URL or path of the external file. |
| type | MIME type of the content. |
| width | Width of the embedded object. |
| height | Height of the embedded object. |
| form | Associates the object with a form. |
| name | Assigns a name to the object for scripting purposes. |
embed or object?
| Question | embed | object |
|---|---|---|
| Fallback if the file cannot be shown | No | Yes, the content inside |
| Closing tag | No | Yes |
| File address attribute | src | data |
| Best for | Quick embeds where you know it will work | Anything readers on phones might open |
In practice, choose object for PDFs, so phone users still get a way to open the file.
Hide the PDF toolbar
You can add settings to the end of the PDF address after a #:
PDF Toolbar Removing Example with <embed>
html
<embed src="https://ik.imagekit.io/html5andcss3/lesson-samples/sample.pdf#toolbar=0&navpanes=0&scrollbar=0" type="application/pdf" width="600" height="500">PDF Toolbar Removing with <object>
PDF Toolbar Removing Example with <object>
html
<object data="https://ik.imagekit.io/html5andcss3/lesson-samples/sample.pdf#toolbar=0&navpanes=0&scrollbar=0" type="application/pdf" width="600" height="500">
<p>Your browser cannot display this PDF. <a href="https://ik.imagekit.io/html5andcss3/lesson-samples/sample.pdf">Download PDF</a></p>
</object>toolbar=0 hides the toolbar, navpanes=0 hides the side panel, and scrollbar=0 hides the scrollbar. These are hints for the browser's PDF viewer, not HTML. Chrome and Edge follow most of them; other browsers may ignore them, so do not rely on them to stop people downloading the file.
Tips
- Always set
widthandheight, so the page does not jump while the file loads. - Many phone browsers cannot show PDFs inside a page at all. Always offer a plain download link too.
- For media, use
<audio>and<video>. For another web page, use an iframe. - Do not add
<param>tags inside<object>. They were for old plugins and are obsolete.
Browser Support
Chrome | Edge | Firefox | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
HTML Embed & Object exercises
Embed a document
Embed the PDF https://ik.imagekit.io/html5andcss3/lesson-samples/sample.pdf with an embed element and say its type, application/pdf.
Result
