Next.js normally builds pages from React components, but sometimes you need to display a separately created .html file directly.
For example, you may need to show a document or render a results page supplied by an external system as it is.
This article walks through loading and displaying static HTML in the
If you want to display a PDF on the web, another approach is to convert it to HTML and show that in an iframe.
A service such as CloudConvert PDF to HTMLโ can perform the conversion.
Place the converted HTML in public to display it easily on a web page through an iframe.
This is particularly useful when the PDF is large or the browser's built-in viewer is unavailable.
Users can also read the content immediately without a PDF viewer.
Loading HTML in an iframe is simple, but keep these points in mind.
Relative paths
: Relative paths to CSS, images, or JavaScript inside the HTML may display incorrectly. Prefer absolute paths such as /images/test.png when correcting them.
Content Security Policy (CSP)
: Organization or browser security policies may block iframe content. Server settings or security headers may need adjustment.
No SEO benefit
: Search engines may have difficulty recognizing HTML loaded through an iframe, so this does not help SEO.
The simplest approach to displaying external HTML in Next.js App Router is to
place it in public and render it through an iframe
.
Formats that are harder to display directly, such as PDFs, can also be converted to HTML and presented in the same way.
Use this approach for a clear purpose; where possible, migrating the HTML into React may be a better choice.