Convert HTML to PDF, free, in your browser
To convert HTML to PDF, the HTML has to be rendered by a browser engine and its pages written out as PDF. Your own browser can do that: paste the HTML or drop an .html file below, check the preview, choose the paper size and margins, and save it as a PDF from the print window. CSS is applied as in the browser, including print rules such as @page and page-break, text stays selectable and links stay clickable. Scripts in the HTML are not run, and the markup is not uploaded.
Your files never leave your device. Processing happens in your browser. How that works.
How it works
- Paste your HTML into the box, or drop an .html file. A fragment such as a single table works as well as a whole page.
- Check the preview, which shows the page at the paper width you chose.
- Set the paper size, orientation, margins and scale.
- Click Save as PDF, choose “Save as PDF” in the print window, and save.
Runs as JavaScript inside this tab. Turn off your connection after the page loads and it still works.
CSS for print: page size, margins and page breaks
Page setup in CSS
The paper size and margins you choose in the tool are written as an @page rule. You can also set them in your own HTML; rules later in the document win.
| CSS | Effect |
|---|---|
@page { size: A4; margin: 20mm; } |
A4 pages with 20 mm margins |
@page { size: 8.5in 11in landscape; } |
US Letter, sideways |
@page :first { margin-top: 40mm; } |
A different margin on the first page |
@media print { nav { display: none; } } |
Hide something only when printing |
Controlling page breaks
| CSS | Effect |
|---|---|
break-before: page; |
Start this element on a new page |
break-after: page; |
Start a new page after it |
break-inside: avoid; |
Keep the element on one page if it fits |
break-after: avoid; on headings |
Keep a heading with the text that follows |
orphans: 2; widows: 2; |
At least two lines of a paragraph at the bottom and top of a page |
thead { display: table-header-group; } |
Repeat a table’s header row on every page (the default) |
The older page-break-before, page-break-after and page-break-inside properties mean the same and are still honoured.
What loads and what does not
| In your HTML | Result |
|---|---|
<style> blocks and style attributes |
Applied |
<link rel="stylesheet" href="https://…"> |
Loaded, if web loading is ticked |
<img src="https://…"> |
Loaded, if web loading is ticked |
<img src="data:image/png;base64,…"> |
Always shown |
<img src="images/logo.png"> (relative path) |
Not available: only the one file was given |
http:// (not secure) addresses |
Blocked by the browser |
<script>, event handlers, <iframe>, <object> |
Removed |
| Web fonts from an https stylesheet | Loaded, if web loading is ticked |
To make an HTML file self-contained, embed images as data URLs and put the CSS in a <style> block.
Paper sizes
| Name | Size | Pixels at 96 per inch |
|---|---|---|
| US Letter | 8.5 × 11 in | 816 × 1056 |
| US Legal | 8.5 × 14 in | 816 × 1344 |
| A4 | 210 × 297 mm | 794 × 1123 |
| A3 | 297 × 420 mm | 1123 × 1587 |
| A5 | 148 × 210 mm | 559 × 794 |
CSS lengths map to paper at 96 pixels per inch: an element 672 px wide exactly fills a US Letter page with ¾ inch margins.
Why use the browser’s print engine
Turning HTML into PDF needs a full browser layout engine. Online converters run one on a server and you upload your file to it. Here the engine is the browser you already have, so layout matches what you see, text remains real text, and private documents stay on your device. The trade-off is one extra click in the print window.
Tips for a clean result
- Use
pt,mmorinfor sizes that must be exact on paper. - Give tables
width: 100%so they follow the page width. - Avoid fixed heights in
vh; a printed page has no viewport. - Set a
<title>: it becomes the suggested file name.
Worked examples
The built-in example
Click Try an example. A short report with a heading, a paragraph with a link, a table and a highlighted note appears in the preview on a US Letter sheet. Save as PDF writes a one-page PDF in which the text can be selected, the link is clickable and the yellow note keeps its background.
A fragment instead of a whole page
Paste only <h1>Minutes</h1><p>Present: …</p>. There is no need for <html> or <body>; the fragment is placed in a page for you.
An email template or receipt
Paste the HTML of the email. Images given as https:// addresses load if web loading is ticked. Untick it to keep the conversion fully offline; the images are then left out.
A wide table that runs off the page
Switch the orientation to Landscape, or set Scale to 80% or 70%. The preview shows the table at the new size before you save.
A multi-page document with chapter breaks
Add <h2 style="break-before: page"> to each chapter heading. Each chapter starts on a new page in the PDF.
An exported page with relative images
A page saved from a website refers to images such as page_files/logo.png. The summary line reports how many files “could not be loaded” for this reason. Open the saved page in your browser and print it from there, or replace the paths with full addresses.
Plain text by mistake
Pasting text with no tags still works: paragraphs and line breaks are kept and the result is a simple, readable PDF.
Something that needs JavaScript
A chart drawn by a script will be blank, because scripts are not run here. Open the page in your browser and press Ctrl+P (Cmd+P on a Mac) there instead.
Frequently asked questions
Why does it open the print window instead of downloading a file?
The PDF is made by your browser’s own print engine, the same one that prints web pages, which is why the text stays selectable, links keep working and every language is supported. Choose “Save as PDF” as the destination and click Save. Nothing is sent to a printer or a server.
Does it run the JavaScript in my page?
No. Scripts are removed and the preview is sandboxed so that nothing in the pasted page can run. Pages that build their content with JavaScript will be empty; open such a page in your browser and use its own Print → Save as PDF instead.
Why are my images or styles missing?
Images and stylesheets given as full https addresses load when “Load images, fonts and styles from the web” is ticked. Files referred to by a relative path, such as images/logo.png, cannot load from a single HTML file, because the rest of the folder is not available. Use full addresses or embed the files as data URLs.
How do I control page breaks?
With CSS, as for printing: break-before: page or page-break-before: always starts a new page, break-inside: avoid keeps a block together, and an @page rule sets size and margins. Rules inside @media print are applied.
Can I convert a web page from its address?
Not from here: a page on another site cannot be fetched by this one, by design of browsers. Open the page itself and press Ctrl+P (Cmd+P on a Mac), then choose Save as PDF. This tool is for HTML you have as code or as a file.
Are background colours printed?
Yes, when “Print background colours” is ticked. Browsers leave backgrounds out by default to save ink; this tool asks for them to be kept.
Is my HTML uploaded?
No. It is rendered in your browser. If your HTML refers to images or fonts on the web and you allow them, your browser requests those files from their own servers, as it would for any web page.
HTML → PDF · last updated · changelog · part of Canned Tuna