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.
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.
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:
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
Method
Fallback Content
Setup Effort
Mobile Support
Best For
Iframe
No
Very low
Weak
Quick desktop previews
Object tag
Yes
Low
Weak
Pages that need a download link fallback
Embed tag
No
Very low
Weak
Legacy templates
PDF.js viewer
Custom
Medium
Good
Developers who want control
Flipbook embed
Built in
Very low
Excellent
Brochures, catalogs, reports
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:
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.
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:
Host the PDF on your own domain.
If you control the server, change the header to allow your site, or send frame-ancestors 'self' https://yourdomain.com.
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
Symptom
Likely Cause
Fix
Blank gray box
Frame blocked by headers
Self host the file or adjust frame-ancestors
Download starts instantly
Content-Disposition: attachment
Serve inline with application/pdf
Works locally, fails live
Mixed content or wrong path
Use HTTPS and an absolute URL
Only page 1 on iPhone
Mobile Safari limitation
Use a viewer library or flipbook
Embed shows nothing on Android
No built in viewer
Add a fallback link or switch method
Console says "refused to display"
CSP or X-Frame-Options
Update server policy
Huge page load time
Large file, no lazy loading
Compress the PDF and add loading="lazy"
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:
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.
Approach
Control
Privacy
Maintenance
Reader Experience
Native iframe
Low
High
None
Varies by browser
Google Docs viewer
Very low
Low
None
Slow, plain
PDF.js
High
High
You own it
Functional, utilitarian
Flipbook
High
High, with passwords
None
Polished, page turning
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
✅ 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.
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.
Task
Raw PDF Embed
Flipbook Embed
Works on iPhone and Android
Often not
Yes
Page turning animation
No
Yes
Password protection
Needs server work
Built in
Custom branding
No
Yes
Reader analytics
None
Professional plan
Lead capture
No
Professional plan
Needs header or CSP changes
Frequently
No
Video and audio on pages
No
Yes
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.
Menus, Brochures, and Reports
Restaurants can embed a menu that updates without touching the website. Try the Restaurant Menu Creator.
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.
Scenario
Recommended Method
One page form for internal staff
Iframe or object tag
Public brochure or catalog
Flipbook
Confidential document with a password
Flipbook with password protection
Custom reader inside your own app
PDF.js
Quick preview on a desktop only site
Iframe 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.