<object>

Embeds an external resource (PDF, image, page) with fallback content in case it fails to load.

Display
inline (replaced element)
Closing tag
Required
Permitted content
Fallback content, displayed when the resource fails to load
On this page

Example

#
HTML
<object data="/pliki/plan-kursu-html.pdf" type="application/pdf" width="320" height="160">
  <p>We can’t display the PDF preview.</p>
  <p><a href="/pliki/plan-kursu-html.pdf">Download the course outline</a></p>
</object>
Preview

In the preview the PDF file is not available, so you see the fallback content, exactly what a user will see when the file fails to load.

Definition and usage

#

The <object> element embeds an external resource: a PDF document, an image, an SVG graphic, or another HTML page. You give the address in the data attribute (not src), the type in type, and the size in width and height.

Its advantage over <embed> is fallback content. Whatever you put between the tags appears when the resource can’t be loaded or displayed. It is the ideal place for a link to download the file.

Like <embed>, the element dates from the days of plugins, and its old attributes for handling them, such as classid and codebase, are obsolete. <iframe> is better for embedding other pages, and <img> for images.

Syntax

#
Syntax
<object data="file.pdf" type="application/pdf" width="…" height="…">
  fallback content
</object>

Attributes

#
  • data

    URL

    The address of the embedded resource. It is the equivalent of the src attribute in other elements.
  • type

    MIME type, e.g. `application/pdf`, `image/svg+xml`

    The type of the resource. It helps the browser decide right away whether it can display it or should show the fallback content.
  • width / height

    number of pixels

    The dimensions of the area in which the resource is displayed.

The element also supports all global attributes, such as class, id, style and hidden.

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Always provide fallback content with a link to the file. On phones the built-in PDF preview doesn’t always work.
  • For videos from services like YouTube or Vimeo, use <iframe>, not <object>.

Related entries

#

Spotted a mistake or missing an example? Write to us.