How to Link a PDF with an HTML a href
Link to a PDF with an HTML anchor, choose whether it opens or downloads, and handle cross-origin links, filenames, accessibility, and common issues.
Put the PDF URL in an anchor element’s href:
<a href="/files/guide.pdf">Read the PDF guide</a>
This creates a normal link. The browser may open the PDF in its built-in viewer, hand it to an external application, or download it, depending on browser settings and the server’s response. To request a download, add the download attribute:
<a href="/files/guide.pdf" download>Download the PDF guide</a>
For the attribute to work as documented, the PDF URL must be same-origin with your page, or use a blob: or data: URL. Use link text that says what the destination is and what activation does. MDN’s anchor reference documents these behaviors.
1. Link to a PDF for viewing
Use an ordinary anchor when readers should be able to open or save the document using their browser’s normal PDF handling:
<p><a href="/documents/annual-report.pdf">Read the annual report (PDF)</a></p>
The href can be a relative path, a root-relative path, or an absolute URL. For example:
<!-- Relative to the current page's URL -->
<a href="files/guide.pdf">Read the guide (PDF)</a>
<!-- From the site's root -->
<a href="/documents/guide.pdf">Read the guide (PDF)</a>
<!-- Absolute URL -->
<a href="https://example.org/files/guide.pdf">Read the guide (PDF)</a>
A relative URL is resolved against the current page URL, so a path that works from one route might resolve differently from another. A root-relative URL starts at the site’s root.
2. Request a download and suggest a filename
Add download when the intended action is saving the PDF rather than navigating to it:
<p><a href="/documents/annual-report.pdf" download="annual-report.pdf">Download the annual report (PDF)</a></p>
The attribute value suggests a filename; it does not guarantee the final name or force every browser to save the file. Browser behavior, user settings, and the server’s Content-Disposition response header can affect the result. If you omit the value, the browser can derive a filename from the URL or response.
For a PDF hosted on another origin, use an ordinary link and describe it as a PDF. MDN documents download for same-origin URLs and blob: and data: URLs; do not promise that a cross-origin link will download just because the attribute is present.
3. Choose the URL and response behavior
Use a URL that resolves to the PDF itself and is accessible to the reader. The registered media type for PDF is application/pdf, as specified by RFC 8118. If you control the server, serve the document with that content type. The response’s content-disposition and browser configuration can influence whether it opens inline or is offered as a download.
| Goal | Markup | What to expect |
|---|---|---|
| Let the browser handle the PDF | <a href="/guide.pdf">Read the guide (PDF)</a> |
Navigation; viewer, external app, or download depends on browser handling. |
| Request a same-origin download | <a href="/guide.pdf" download>Download the guide (PDF)</a> |
Requests download treatment; headers and browser settings still matter. |
| Suggest a saved name | <a href="/guide.pdf" download="guide-2026.pdf">Download the guide (PDF)</a> |
Suggests a filename, but does not guarantee it. |
4. Make the link clear and accessible
Write link text that makes sense out of context and identifies both the document and the action. For example:
Read the accessibility report (PDF)for a normal link.Download the accessibility report (PDF)for a requested download.
Avoid vague labels such as “click here.” People may navigate by links alone, and identifying a non-HTML file or download helps set expectations. This guidance is covered in MDN’s anchor accessibility notes.
5. Check the implementation
- Open the page and inspect the rendered link. Confirm the visible text identifies the PDF and the intended action.
- Follow the link. Check that the URL resolves and the PDF opens or downloads as expected in your target browsers.
- If you use
download, confirm the link is same-origin (or ablob:/data:URL) and check the actual saved filename. - If you control the file host, inspect the response headers. The media type should be
application/pdf; content disposition may affect inline versus attachment behavior.
6. Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The link opens a not-found page | The path is incorrect or a relative path resolves from an unexpected directory. | Check the final URL in the browser. Use a root-relative path such as /documents/guide.pdf if the file is under the site root. |
| The PDF opens in a tab instead of downloading | The browser is using its PDF viewer, the URL is cross-origin, or response/browser settings favor viewing. | For a same-origin file, request download with download. Check response headers and test in the target browser; the attribute is not a universal override. |
| The downloaded filename is different | The attribute value is only a suggestion; the response header or browser may choose another name. | Check the server’s Content-Disposition filename and browser behavior. Do not rely on markup alone to guarantee a name. |
| The browser shows unreadable text or downloads an unexpected file | The URL may point to an error page or the server may return an incorrect media type. | Verify the response body is the PDF and serve it with application/pdf. |
| The download attribute seems ignored | The destination may be cross-origin, or browser handling may differ. | Use it for a same-origin, blob:, or data: URL and treat it as a request, not a guarantee. |
7. Or skip the browser setup
If you need a PDF capture of a web page rather than a link to an existing PDF, ScreenshotNeo provides a website screenshot API that can return PDFs. One GET request is enough; see the API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.pdf
ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture. Bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents take screenshots, and 1,000 screenshots per month are free with no card; paid plans start at $5 for 3,000. Sign up for free.
8. FAQ
What do I put in the href for a PDF?
The URL of the PDF, such as /files/guide.pdf or an absolute URL to the document.
Does download always force a download?
No. It requests download behavior under the documented origin conditions, and browser settings and response headers can still affect the outcome.
Can I link to a PDF on another website?
Yes. Use its URL in href. Treat it as ordinary navigation and do not rely on download for a cross-origin URL.
What content type should a PDF use?
application/pdf, the registered media type for PDF.


