pdf conversionflipbooktutorialsonline tools

Embed PDF in HTML: Iframe, Object Tag, Not Working Fixes, and Flipbook Option

Copy working iframe and object tag code to show a PDF on your page, fix the blank gray box and blocked frame errors, and see why a page turning flipbook gives mobile visitors a far better reading experience than a raw embed.

Embed PDF in HTML: Iframe, Object Tag, Not Working Fixes, and Flipbook Option
Cristian Da Conceicao

You uploaded a PDF, pasted a snippet, refreshed the page, and got a blank gray box. It happens to almost everyone who tries to embed PDF in HTML for the first time. The good news: the fix usually takes under five minutes, and when it doesn't, there is a cleaner route. This article shows you working iframe and object tag code, the exact reasons embeds break, and a Flipbooks AI option that skips the browser quirks entirely.

Developer typing code to embed a PDF viewer frame on a web page

The Fastest Way to Embed a PDF

Three native HTML elements can display a PDF: <iframe>, <object>, and <embed>. All three rely on the visitor's browser having a built in PDF viewer. Desktop Chrome, Edge, Firefox, and Safari do. Most mobile browsers do not, and that gap causes the majority of complaints.

Basic Iframe Code

The iframe is the most popular choice because it is simple and predictable. Drop this into your page:

<iframe
  src="/files/report.pdf"
  width="100%"
  height="700"
  title="Annual report PDF"
  loading="lazy">
</iframe>

A few details matter here:

  • src can be a relative path or a full HTTPS URL.
  • title helps screen readers and improves accessibility scores.
  • loading="lazy" delays the download until the frame is near the viewport, which protects your page speed.
  • height needs a real value. An iframe with no height collapses to a thin strip.

Object Tag Method

The <object> tag gives you a built in fallback, which is its biggest advantage over the iframe:

<object
  data="/files/report.pdf"
  type="application/pdf"
  width="100%"
  height="700">
  <p>Your browser cannot display this PDF.
  <a href="/files/report.pdf">Download it here</a>.</p>
</object>

If the browser can't render the file, the content inside the tag shows instead. That is a much friendlier outcome than an empty rectangle.

Embed Tag and Why to Skip It

The <embed src="file.pdf" type="application/pdf"> tag works in the same browsers, but it has no fallback content and is treated as a legacy element. Use it only when you maintain an old template that already depends on it.

💡 Pro tip: Add #toolbar=0&navpanes=0 to the end of the PDF URL in Chromium based browsers to hide the toolbar and side panel. Example: src="/files/report.pdf#toolbar=0&navpanes=0". Firefox and Safari ignore some of these parameters, so test in each.

Quick Comparison of Embed Methods

MethodFallback ContentSetup EffortMobile SupportBest For
IframeNoVery lowWeakQuick desktop previews
Object tagYesLowWeakPages that need a download link fallback
Embed tagNoVery lowWeakLegacy templates
PDF.js viewerCustomMediumGoodDevelopers who want control
Flipbook embedBuilt inVery lowExcellentBrochures, catalogs, reports

Printed PDF pages on a wooden table beside a laptop

Make the Embed Responsive

A fixed pixel height looks fine on your monitor and terrible on a phone. Two small changes solve most layout issues.

Use a Fluid Wrapper

Wrap the iframe in a container that keeps a stable proportion and scales with the screen:

<div class="pdf-wrap">
  <iframe src="/files/report.pdf" title="Report"></iframe>
</div>

<style>
.pdf-wrap { position: relative; width: 100%; aspect-ratio: 3 / 4; max-height: 90vh; }
.pdf-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
</style>

A 3:4 ratio suits portrait documents like brochures and forms. For landscape slide decks, switch to 16 / 9.

Set a Sensible Minimum Height

Even with a fluid wrapper, tall documents need room. Set min-height: 500px so readers do not squint at a postage stamp. On phones, consider linking to the file or a flipbook instead, because scrolling inside a scrolling page is frustrating.

Why Your PDF Is Not Working

When an embed fails, the cause almost always falls into one of a handful of buckets. Work through them in order.

Frustrated developer rubbing forehead while looking at a laptop in a coworking space

Blocked by X-Frame-Options

If you embed a PDF hosted on someone else's server, the response may include X-Frame-Options: DENY or SAMEORIGIN, or a Content-Security-Policy: frame-ancestors rule. The browser then refuses to draw the file and you see a blank frame or a message like "refused to connect."

Fixes:

  1. Host the PDF on your own domain.
  2. If you control the server, change the header to allow your site, or send frame-ancestors 'self' https://yourdomain.com.
  3. Check your own site's CSP. A strict frame-src or object-src directive can block your own embed.

Wrong Content-Type or Forced Download

If the server sends Content-Disposition: attachment, the browser downloads the file instead of showing it. A wrong Content-Type such as application/octet-stream has the same effect.

Open the browser's developer tools, go to the Network tab, click the PDF request, and inspect the response headers. You want Content-Type: application/pdf and either no Content-Disposition or inline.

Mixed Content: HTTP on an HTTPS Page

A secure page cannot load an http:// PDF inside a frame. Browsers block it silently. Change the URL to https://, or move the file to a host that supports TLS.

Mobile Browsers Ignore the Embed

This is the one people forget. iOS Safari shows only the first page of an embedded PDF, with no easy scrolling. Many Android browsers show nothing at all, or offer a download prompt. No code change fixes it, because the viewer itself is missing.

⚠️ Warning: More than half of web traffic comes from phones. If your PDF matters to your business, test the embed on a real device before you publish.

Symptoms and Fixes at a Glance

SymptomLikely CauseFix
Blank gray boxFrame blocked by headersSelf host the file or adjust frame-ancestors
Download starts instantlyContent-Disposition: attachmentServe inline with application/pdf
Works locally, fails liveMixed content or wrong pathUse HTTPS and an absolute URL
Only page 1 on iPhoneMobile Safari limitationUse a viewer library or flipbook
Embed shows nothing on AndroidNo built in viewerAdd a fallback link or switch method
Console says "refused to display"CSP or X-Frame-OptionsUpdate server policy
Huge page load timeLarge file, no lazy loadingCompress the PDF and add loading="lazy"

Top-down view of a desk with laptop, notebook sketches and phone showing a blank browser page

Viewer Libraries and Fallbacks

If the native approach keeps failing, put a rendering layer between the file and the browser.

Google Docs Viewer Fallback

You can load a public PDF through Google's viewer:

<iframe
  src="https://docs.google.com/gview?url=https://yourdomain.com/files/report.pdf&embedded=true"
  width="100%" height="700">
</iframe>

It works on more devices, but it needs a publicly reachable file, it can be slow, and you hand control of the experience to a third party. Don't use it for private or confidential documents.

Self Hosted PDF.js

Mozilla's open source PDF.js renders each page to a canvas, so it works on nearly every device. You host the viewer files, point them at your PDF, and embed the viewer in an iframe. The tradeoff is maintenance: you update the library, style the interface, and test it yourself.

ApproachControlPrivacyMaintenanceReader Experience
Native iframeLowHighNoneVaries by browser
Google Docs viewerVery lowLowNoneSlow, plain
PDF.jsHighHighYou own itFunctional, utilitarian
FlipbookHighHigh, with passwordsNonePolished, page turning

Person holding a smartphone in a cafe showing a magazine style page

Why a Flipbook Beats a Raw Embed

A raw PDF embed shows a document. A flipbook shows a publication. Pages turn, the layout adapts to the screen, and the reader doesn't have to pinch and zoom through a scroll box.

What Readers Actually See

Instead of a gray rectangle with a toolbar, visitors get a branded viewer with smooth page flips, zoom, full screen mode, and fast loading. It behaves the same on a laptop, a tablet, and a phone, so the mobile problems from earlier simply disappear.

What You Gain as a Publisher

  • Mobile responsive design out of the box
  • No watermarks, ever
  • Password protection for private content
  • Custom branding with your colors and logo
  • Embedded video and audio inside pages
  • Offline downloads for readers on the move
  • Analytics and lead generation on the Professional plan

Open printed magazine with a page mid turn on an oak table

✅ Best practice: Keep the original PDF as a download option next to the flipbook. Readers who want to print or archive the file get it, and everyone else gets the better viewing experience.

How to Embed a Flipbook in HTML

Here is the whole workflow with the PDF to Flipbook Converter. No server settings, no header debugging.

Marketing manager uploading a file on a laptop at a standing desk

Step 1: Create Your Account

Head to Flipbooks AI and create an account. You can see what each plan includes on the pricing page.

Step 2: Upload the PDF

  1. Open the dashboard and choose the upload option.
  2. Drag your PDF into the upload area, or pick it from your computer.
  3. Wait a few moments while the pages convert. Text stays sharp and images keep their quality.
  4. Preview the result in the viewer.

💡 Pro tip: Compress oversized images in the source PDF first. A lighter file means a faster first page for your visitors.

Step 3: Customize the Look

  • Set your brand colors and add your logo
  • Choose a background that suits your page
  • Adjust page flip effects and sound
  • Add video, audio, and links to individual pages

You do not need a designer. The settings panel shows changes live, so you see the final result before publishing.

Step 4: Grab the Embed Code

Open the share panel and choose the embed option. You will get a snippet that looks much like a standard iframe:

<iframe
  src="YOUR-FLIPBOOK-LINK"
  width="100%"
  height="650"
  frameborder="0"
  allowfullscreen
  title="My flipbook">
</iframe>

Paste it into any page that accepts HTML: WordPress, Webflow, Wix, Shopify, or a hand coded site. If you want more detail, the Embed Flipbook on Website tool page explains the options.

Other sharing choices include a direct link for email and social posts, plus password protection when the content is meant for a limited audience.

Step 5: Turn On Professional Extras

On the Professional plan you can switch on analytics to see which pages people read, lead generation forms to capture emails before access, and offline downloads for readers who want a copy.

TaskRaw PDF EmbedFlipbook Embed
Works on iPhone and AndroidOften notYes
Page turning animationNoYes
Password protectionNeeds server workBuilt in
Custom brandingNoYes
Reader analyticsNoneProfessional plan
Lead captureNoProfessional plan
Needs header or CSP changesFrequentlyNo
Video and audio on pagesNoYes

Three colleagues reviewing a website on a desktop monitor

Real Examples Worth Copying

Different documents call for different tools. Here is how common scenarios play out.

Product Catalogs

A boutique owner who uploads a seasonal catalog gets a page turning version that feels like the printed edition, right on the product page. The Product Catalog Generator and Digital Catalog Maker are built for exactly this.

Boutique owner holding a tablet showing a digital catalog

Menus, Brochures, and Reports

When a Plain Embed Is Enough

Not every file needs a viewer upgrade. A one page internal form, a short legal notice, or a document that only desktop staff will open can stay as a simple iframe or object tag. Match the tool to the audience.

ScenarioRecommended Method
One page form for internal staffIframe or object tag
Public brochure or catalogFlipbook
Confidential document with a passwordFlipbook with password protection
Custom reader inside your own appPDF.js
Quick preview on a desktop only siteIframe with a download link

Pick Your Method Today

If you only need a desktop preview, use the object tag with a download link inside it, make the wrapper responsive, and check your headers. If the audience is public and a lot of them are on phones, skip the troubleshooting and publish a flipbook instead.

Ready to try it? Get started for free on Flipbooks AI, browse all flipbook tools, or compare pricing plans to pick what works for you. When you're ready to pay for extras, create your account and head to pricing in one click.

Share this article

Choose your language

FreeTurn any PDF into a flipbookFree, No Credit CardRealistic Page TurnsShare With One LinkCreate a Flipbook