Free Standalone HTML5 & Print-CSS PDF Templates
Exports renderer-agnostic HTML5 + @page print CSS with Mustache/Handlebars {{variable}} placeholders. Output size and speed depend on your print engine — warm headless Chromium renders 19 pages in 818 ms (453.6 KB; 581 ms single-page), while html2pdf.js rasterizes pages into images.
Install: npm install html2pdf.js | Runtime: Node.js (HTML5 + Print CSS) | Version: HTML5 | Popularity: 450k/mo installs
Works with: html2pdf.js, Browser window.print(), Gotenberg, PrinceXML, wkhtmltopdf
How HTML5 & CSS Paged Media Templates Work in CodePDF
Emits zero-dependency HTML5 markup with scoped CSS rules, @page size/margin declarations, print-color-adjust: exact, and clean {{var}} bindings compatible with any template engine.
- Works out of the box with html2pdf.js, Gotenberg Docker containers, Handlebars, Jinja2, Blade, or Liquid
- Print-tested @page dimensions prevent awkward mid-card page splits
- Clean semantic markup with inline SVG barcodes and zero external CSS framework bloat
Quick Start: Generate PDFs with HTML / CSS
Install HTML5 & CSS Paged Media (HTML5 + Print CSS), then run the code CodePDF exports for any template:
npm install html2pdf.js # or: npm install puppeteer
- Save the generated markup as document.html.
- Open it in a browser to preview, then print to PDF.
- For automation, use Puppeteer: await page.setContent(html); await page.pdf({ path: 'out.pdf' }).
- Or render with Playwright, html2pdf.js, or Python WeasyPrint.
Example HTML / CSS Output (Professional Invoice)
Compiled directly from the Professional Invoice template (HTML5 + Print CSS):
<!DOCTYPE html>
<!-- This code is generated using codepdf.dev -->
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Professional Invoice</title>
<style>
* { box-sizing: border-box; }
body, p, h1, h2, h3, h4, h5, h6, ul, ol, li { margin: 0; padding: 0; }
body { font-family: Helvetica, Arial, sans-serif; background: #f3f4f6; }
@page { size: A4 portrait; margin: 0; }
.pdf-page { position: relative; display: flex; flex-direction: column; width: 210mm; min-height: 297mm; margin: 0 auto 16px; background: #fff; overflow: hidden; }
.pdf-page + .pdf-page { page-break-before: always; }
.pdf-list li { break-inside: avoid; page-break-inside: avoid; }
.pdf-text-flow { white-space: pre-wrap; overflow-wrap: break-word; }
@media print { .pdf-page { display: block; overflow: visible; margin: 0; box-shadow: none; page-break-inside: auto; } .pdf-list { display: block; } }
.pdf-page > * { box-sizing: border-box; }
.pdf-view { display: -webkit-box; display: flex; -webkit-box-orient: vertical; flex-direction: column; }
.pdf-table { display: table; width: 100%; border-collapse: collapse; }
.pdf-table thead { display: table-header-group; }
.pdf-table tr { page-break-inside: avoid; break-inside: avoid; }
.pdf-table thead tr { border-bottom: 1pt solid #d1d5db; }
.pdf-table tbody tr { border-bottom: 0.5pt solid #e5e7eb; }
.pdf-row { display: table-row; }
.pdf-cell { display: table-cell; padding: 3.5pt 4pt; vertical-align: top; }
.pdf-image { display: block; }
.pdf-field { display: flex; flex-direction: column; }
.pdf-field-label { font-size: 7.5pt; color: #6b7280; margin-bottom: 2pt; line-height: 1.2; }
.pdf-input { border: 1pt solid #d1d5db; border-radius: 3pt; padding: 3.5pt 5pt; background: #fff; line-height: 1.25; }
// … (172 more lines in full generated file)
Custom Fonts in HTML / CSS
Declare @font-face rules with HTTPS URLs, local paths, or Google Fonts stylesheets in <head>.
- Include one @font-face block per weight/style inside <style>.
- Use font-display: swap and verify MIME types when serving .woff2/.ttf assets.
- Await document.fonts.ready before headless print-to-PDF export.
Official documentation: HTML / CSS docs
HTML / CSS Benchmark Results
Measured on CodePDF’s 26-component, 19-page All-Components Dynamic Multi-Page Flow Stress Test (same document across all 22 libraries).
| Metric | HTML / CSS | Rank (of 22) |
|---|---|---|
| Wall-clock time | 818 ms | 16th fastest |
| CPU time | 1.22 s | 17th lowest |
| Peak RAM | 196.3 MB | 18th lowest |
| PDF file size | 453.6 KB | 20th smallest |
- Engine type
- Browser (Chromium)
- Under the hood
- Standalone HTML5 + @page Print CSS (benchmarked via headless Chromium print pipeline)
- Runs in
- Any HTML-to-PDF renderer (Browser print, Gotenberg, Chromium, WeasyPrint)
- Verdict
- Renderer-agnostic HTML5 + @page CSS; warm Chromium print finishes 19 pages in 818 ms (453.6 KB; 581 ms single-page).
Under the Hood & Benchmark Highlights
- Exports portable HTML5 + @page CSS with Mustache/Handlebars {{var}} placeholders rather than locking you into one PDF engine.
- In our harness (rendered via headless Chromium), output matched Playwright at 296.0 KB across 10 pages in 2.43s (~176 MB RAM).
- Quality and speed depend entirely on your chosen print runner: Chromium/WeasyPrint emit sharp vector text, while html2pdf.js rasterizes pages into blurry images via html2canvas.
Good to Know (HTML / CSS Caveats)
- Markup only — brings no renderer: Pair the exported HTML with a print engine (browser window.print(), Puppeteer/Playwright, Gotenberg, WeasyPrint, or PrinceXML).
- Avoid html2pdf.js if you need sharp selectable text: html2pdf.js rasterizes HTML via html2canvas into a JPEG/PNG inside the PDF, resulting in larger, non-searchable files.
- Browser print dialogs vary: Users printing via Ctrl+P/Cmd+P must keep "Background graphics" enabled unless rendered headless with printBackground: true.
Popular HTML / CSS PDF Templates
- Professional Invoice HTML / CSS template — Line-item invoice with billing details, totals and payment terms.
- Modern Resume HTML / CSS template — Two-column executive resume with dark slate sidebar, impact KPI strip, skill pills, and portfolio QR.
- Payment Receipt HTML / CSS template — Clean transaction receipt with payment method details, item breakdown and verified badge.
- Restaurant Menu HTML / CSS template — Sophisticated culinary dining menu with category sections, descriptions, dietary badges and prices.
- Event Flyer HTML / CSS template — High-contrast poster with headline, agenda, speakers and RSVP block.
- Business Letter HTML / CSS template — Formal letterhead with sender block, subject line and signature area.
All 100 CodePDF templates export to HTML5 & CSS Paged Media. Browse them by category: Career (5) · Business (6) · Education (7) · Marketing (6) · Human Resources (8) · Finance (7) · Legal (8) · Healthcare (10) · Logistics (6) · Real Estate (6) · Hospitality (4) · Operations (5) · Technology (5) · Banking (9) · Non-Profit (4) · Personal (3) · Compliance & Enterprise (1), or see the full template gallery.
HTML / CSS Template FAQs
Can I use these HTML templates with Handlebars, Jinja2, or Gotenberg?
Yes! Dynamic bindings are emitted using clean {{variable}} syntax that drops directly into Handlebars, Mustache, Jinja2, Liquid, or Gotenberg pipelines.
Are styles self-contained in a single HTML file?
Yes. Every exported HTML template embeds a complete <style> block with @page print rules and Google Fonts links so it renders identically anywhere.
Do these HTML templates work with browser Ctrl+P / window.print()?
Yes — @page size and print-color-adjust rules ensure clean A4 or US Letter printing directly from Chrome, Edge, Safari, or Firefox.
HTML / CSS vs Other Node.js PDF Libraries
- @react-pdf/renderer — 1.06 s, 237.3 MB RAM, 126.8 KB PDF. #2 smallest multi-page PDF overall (126.8 KB across 18p; 12 ms single-page, 1.06s stress) with Yoga Flexbox; run server-side in Next.js.
- pdf-lib — 334 ms, 209.7 MB RAM, 203.8 KB PDF. Runs in browsers & Edge Workers and edits/merges existing PDFs (5.3 ms single-page; 334 ms / 203.8 KB across 20p).
- jsPDF — 120 ms, 98.3 MB RAM, 157.4 KB PDF. Fastest Node.js/browser JS engine in stress test (120 ms for 22p, 3.5 ms single-page, 98.3 MB RAM); custom TTFs require base64 VFS.
- pdfmake — 189 ms, 183.7 MB RAM, 165.5 KB PDF. Declarative JSON tables & automatic pagination in 189 ms (27p, 165.5 KB; 4.4 ms single-page); VFS fonts add weight to browser bundles.
- PDFKit (Node.js) — 140 ms, 125.5 MB RAM, 162.6 KB PDF. Fastest server-only Node.js stream writer on single-page invoices (2.8 ms / 2.6 KB; 140 ms / 125.5 MB RAM across 22p).
- Puppeteer — 1.35 s, 263.2 MB RAM, 841.2 KB PDF. Full Chrome CSS fidelity, but 841.2 KB PDF (#2 largest), 263.2 MB RAM (highest), 1.35s warm render (+ cold Chrome launch & ~350 MB binary).
- Playwright — 883 ms, 203.8 MB RAM, 452.2 KB PDF. Beat Puppeteer on pure PDF render speed (883 ms vs 1.35s), RAM (204 vs 263 MB), and PDF size (452 vs 841 KB); Chromium-only.
See the full 22-library benchmark rankings · Compare all supported PDF libraries