How to Convert an Angular View to Static HTML
Convert Angular routes to static HTML with prerendering, renderModule, deployment guidance, troubleshooting, and a browser-free ScreenshotNeo option.

For a complete Angular route, the supported way to produce static HTML is build-time prerendering (Static Site Generation, or SSG). Angular renders selected routes during the build and writes HTML files that can be deployed to static hosting. For an HTML string from code, Angular’s renderModule API bootstraps an NgModule application and serializes the page content.
An arbitrary live component instance is different. Angular does not provide a universal export button that turns any component view into standalone HTML. Choose the route-level prerendering path when you need deployable pages; use renderModule when you need serialized application output from a server-side render.
Choose the right rendering mode
| Mode | When rendering happens | Best for | Deployment |
|---|---|---|---|
| Prerender (SSG) | During the build | Pages whose data is known at build time and is shared by visitors | Static files on a CDN or web server; no Node server required with static output |
| SSR | For each request | Request-specific, user-specific, or frequently changing content | Server runtime required |
| CSR | In the browser | Highly interactive applications that depend on browser APIs | JavaScript bundle plus an application shell |
Prerendering gives inexpensive, cacheable files, but every route variant increases build time and output size. SSR handles request-time data but adds runtime work and hosting requirements. Static HTML also does not execute Angular event handlers by itself; hydration or client-side JavaScript is still needed for interactivity.
Prerequisites and project setup
- Use the Angular CLI version that matches your project’s installed Angular major version.
- Commit or back up the working tree before changing the build configuration.
- Make sure data required by prerendered pages can be fetched during the build.
- Audit libraries for browser-only globals such as
window,document, andlocalStorage.
Add Angular’s SSR and prerendering support to an existing application:
ng add @angular/ssr
For a new application, create it with SSR enabled:
ng new my-app --ssr
Angular’s SSR guide documents the current generated files and configuration. Check that guide for the exact configuration shape used by your installed major version: Angular server-side rendering.
Prerender a complete route
Define a server route with RenderMode.Prerender. In a standalone application, a typical route configuration looks like this:

import { RenderMode, ServerRoute } from '@angular/ssr';
export const serverRoutes: ServerRoute[] = [
{
path: '',
renderMode: RenderMode.Prerender,
},
{
path: 'about',
renderMode: RenderMode.Prerender,
},
{
path: 'account',
renderMode: RenderMode.Server,
},
{
path: '**',
renderMode: RenderMode.Client,
},
];
Use prerendering for routes that can be generated once and served to everyone. Use RenderMode.Server for pages that depend on request headers, cookies, authentication, or other request-time values. Use RenderMode.Client when the route should remain browser-rendered.
Register the server routes using the provider generated by the CLI. The exact filename can differ between Angular versions, so keep the structure produced by ng add @angular/ssr and replace only the route definitions you need.
Prerender parameterized routes
A route such as products/:id cannot produce every possible document unless the build knows which IDs to render. Supply concrete parameter values with getPrerenderParams:
import { RenderMode, ServerRoute } from '@angular/ssr';
export const serverRoutes: ServerRoute[] = [
{
path: 'products/:id',
renderMode: RenderMode.Prerender,
async getPrerenderParams() {
const response = await fetch('https://example.com/build-products.json');
const products: Array<{ id: string }> = await response.json();
return products.map(product => ({ id: product.id }));
},
},
];
The returned objects identify the URL parameters Angular should materialize. The product data and parameter list must be available during the build. If the source API is unavailable, the build can fail or produce an incomplete set of pages; make the build dependency explicit in CI and decide whether stale checked-in data is an acceptable fallback.
Emit static files with outputMode: "static"
When deployment consists only of generated files, set the application’s server output mode to static in the Angular build configuration:
{
"projects": {
"my-app": {
"architect": {
"build": {
"options": {
"outputMode": "static"
}
}
}
}
}
}
Angular’s static output mode emits prerendered HTML without generating a server file or requiring a Node.js server. The exact location of this option depends on the workspace configuration generated for your Angular version. Run the production build:
ng build
Inspect the generated output directory (commonly under dist/). You should find an HTML document for each prerendered route, along with JavaScript, CSS, and asset files. Upload that directory to static hosting or a CDN, configure fallback routing as required by your host, and rebuild whenever build-time content changes.
Render an Angular application to an HTML string
When another program needs serialized markup rather than files, use @angular/platform-server’s renderModule. Angular documents it as: “Bootstraps an application using provided NgModule and serializes the page content to string.” See the renderModule API reference.
import 'zone.js/node';
import { renderModule } from '@angular/platform-server';
import { AppServerModule } from './src/main.server';
import { readFile } from 'node:fs/promises';
async function render() {
const document = await readFile('./src/index.html', 'utf8');
const html = await renderModule(AppServerModule, {
document,
url: '/about',
});
await Bun.write('./out/about.html', html);
}
render().catch(error => {
console.error(error);
process.exitCode = 1;
});
Use a document template containing the application root element (for example, <app-root></app-root>). The url option determines the route rendered by the application. This API bootstraps an NgModule application; verify compatibility before treating it as a way to render an isolated standalone component instance.
Converting one component or view instance
If you have a component object created inside a running browser application, first decide whether you need a route document or only the component’s data representation.
- For a page that should be indexable and deployable, put the component in a route and prerender that route.
- For a reusable fragment, create a dedicated route or server-rendered entry point that supplies the required inputs.
- For data export, serialize the component’s model to JSON and generate HTML with a server-side template.
- For a visual record of the rendered browser state, capture the page after it has loaded; this produces an image or PDF rather than HTML source.
Do not solve server rendering by mutating the DOM directly. Angular warns that direct DOM manipulation is unsafe for SSR and prerendering, and assigning untrusted content to innerHTML can introduce XSS. Keep output in Angular templates and trusted bindings. Angular’s Renderer2 APIs do not provide general DOM manipulation support in SSR or build-time prerendering contexts.
Make the rendered HTML useful
Supply build-time data
Fetch content in route loaders, resolvers, or the server-rendered application so the data exists when the prerender runs. Avoid code that waits for a browser-only event before inserting the primary content.
Keep browser APIs behind platform checks
import { isPlatformBrowser } from '@angular/common';
import { Inject, PLATFORM_ID } from '@angular/core';
constructor(@Inject(PLATFORM_ID) platformId: object) {
if (isPlatformBrowser(platformId)) {
// Browser-only work belongs here.
}
}
Hydrate when interactivity matters
Hydration lets the browser reuse server-rendered markup and attach Angular behavior. Without client JavaScript, links may work as ordinary HTML links, but event handlers, forms, and dynamic updates will not run.
Use stable URLs
Prerendered files map to concrete paths. Normalize trailing slashes, configure redirects once at the host, and ensure asset URLs work when a document is served from a nested route.
Build and deployment checklist
- Run
ng buildin a clean environment. - Confirm every expected route has an HTML file.
- Open generated files and verify title, canonical URL, headings, and primary content are present without JavaScript.
- Test JavaScript hydration separately: forms, navigation, menus, and data refresh.
- Serve the output directory with your host’s static-file server or CDN.
- Set long cache lifetimes for hashed assets and a deliberate invalidation policy for HTML.
- Rebuild and redeploy when build-time data changes.

Or skip the browser setup
If your goal is a visual capture of the rendered Angular page rather than reusable HTML files, ScreenshotNeo returns a screenshot or PDF from one GET request. It handles the browser for you; it does not turn a page into editable HTML.
cURL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://your-angular-site.example/about -o shot.webp
Python:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://your-angular-site.example/about"}, timeout=90)
open("shot.webp", "wb").write(r.content)
Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://your-angular-site.example/about' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));
See the ScreenshotNeo API documentation for all options. Cookie and consent banners are accepted and removed before capture, along with more than 60 known consent platforms, newsletter popups, and chat widgets. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed; response headers report the page verdict and billing status. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots each month without a card; paid plans start at $5 for 3,000 screenshots.
Create a free ScreenshotNeo account and start with 1,000 screenshots per month at no charge.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| No HTML file for a route | The route is client-rendered, parameter values were not supplied, or the route was not reachable during the build. | Set RenderMode.Prerender, implement getPrerenderParams for dynamic segments, and inspect build logs. |
Build fails with window is not defined |
Browser-only code executes during prerender. | Guard it with isPlatformBrowser or move it into a browser-only lifecycle path. |
| HTML contains a loading shell only | Data arrives after the server render or depends on a browser event. | Fetch required data during server rendering or prerender generation and provide loading states only for optional content. |
| Static host returns 404 on refresh | The host does not map the requested path to the generated document. | Upload the route file structure and configure clean-URL fallback or redirects according to the host. |
| Buttons do nothing | Static HTML has no Angular runtime attached. | Ship the client bundle and enable hydration or client bootstrap. |
| Different users need different HTML | Prerender output is shared and created at build time. | Use request-time SSR or client-side data loading for personalized content. |
| Unsafe markup appears in output | Untrusted content was inserted directly into the DOM. | Use Angular bindings and sanitize or validate content before rendering; avoid direct innerHTML. |
Performance, reliability, and cost
- Build performance: Each prerendered URL adds rendering work. Large parameter lists can make builds and deployments slower, so prerender the routes that benefit most and use SSR or CSR for the rest.
- Delivery performance: Static files can be cached by browsers and CDNs. HTML invalidation should match your content update schedule.
- Reliability: A static deployment removes request-time rendering failures, but the build now depends on every data source used during generation. Add retries or a controlled data snapshot where appropriate.
- Browser compatibility: SSR and prerendering execute outside a normal browser. Test third-party widgets and code that assumes DOM APIs.
- Cost: Static hosting generally avoids an always-on application server. SSR trades that simplicity for request-time compute and runtime operations.
- Screenshot capture: ScreenshotNeo lets you choose caching TTLs, wait conditions, blocked resource types, viewport and device settings, and image format. Only clean successful captures are billed.
FAQ
Does prerendering create HTML for every possible Angular route?
No. Angular generates the routes configured for prerendering. Dynamic routes require a finite list from getPrerenderParams.
Can static HTML keep Angular click handlers?
Not by itself. Include the client bundle and hydrate or bootstrap Angular in the browser.
Should I use SSR or prerendering for a logged-in dashboard?
Usually SSR or client rendering, because the response varies by user and request. Prerendering is intended for shared build-time output.
Can renderModule render a standalone component?
The documented API bootstraps an NgModule application. Wrap the component in an application entry point or use the prerendering architecture supported by your Angular version.
Does ScreenshotNeo return static HTML?
No. It captures the rendered page as PNG, JPEG, WebP, or PDF. Use Angular prerendering when you need deployable or editable HTML.


