Embedding a PDF file

PDF files may also be embedded in a web page like an image. The standards-compliant markup for embedding a PDF is:

<object type="application/pdf" data="directions.pdf" width="450"
height="600">
</object>

Browsers that use the Netscape plug-in architecture may require the nonstandard embed element to display the PDF inline. The href attribute is added so multipage PDF files will open in the reader if the image is clicked. (In Internet Explorer, multipage PDFs are accessible inline using the embedded Acrobat Reader controls for paging through the file.)

It is common for web authors to combine object and embed elements to cover all the bases like this:

<object type="application/pdf" data="directions.pdf" width="450"
height="600">
  <embed src="directions.pdf" width="450" height="400" href="directions.
pdf">
    <noembed><a href="directions.pdf">Link to documentation (PDF)</a></
noembed>
  </embed>
</object>

Warning

Be aware that embed is a nonstandard element that will prevent an (X)HTML document from validating. We are moving toward a standards-compliant Web in which the object element alone will be sufficient, but for the time being, the embed element is still being used to ensure cross-browser support of embedded media.

Get Web Design in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.