HTML to PDF

Paste HTML or open an .html file. Choose the paper, then press Save as PDF and pick “Save as PDF” in the print dialog. The preview shows your HTML before it is printed.

How it works

Your HTML is rendered in a sandboxed frame on this page. When you press Save as PDF, that frame asks your browser to print it, and the browser’s print dialog opens. Choosing Save as PDF as the printer writes the file. The PDF is made by your browser’s own print engine, not by this site.

The paper, orientation and margins you pick become a CSS @page rule. It is placed before your own CSS, so if your HTML has its own @page rule, yours wins. Background colours are kept, so the PDF matches the preview.

The frame cannot load anything from the network. Stylesheets, images and web fonts linked by URL are not loaded, and the page lists each one it blocked. Put your CSS in a style tag and your images in as data: URLs. Fonts installed on your device still work.

How to use it

  1. 1 Paste HTML into the box, or open an .html file from your device.
  2. 2 Choose A4 or US Letter, portrait or landscape, and the margins.
  3. 3 Check the preview. If a resource was blocked, the page lists it.
  4. 4 Press Save as PDF. In the print dialog, choose Save as PDF (Chrome, Edge) or Save to PDF (Firefox) as the printer, then save.

Good to know

  • In Chrome and Edge, turn off Headers and footers under More settings, or the PDF gets the date and a title at the top of each page.
  • Use break-before: page on an element to start it on a new page, and break-inside: avoid to keep a block on one page.
  • Put a table’s heading row in a thead. Most browsers repeat it at the top of every printed page.
  • The preview is as wide as the panel, not the paper, so lines may break in different places in the PDF.

Browser support

  • Chrome 94 and later
  • Firefox 93 and later
  • Safari 16.4 and later
  • Edge 94 and later

These are the oldest versions with everything the tool uses. They are worked out from the tool itself, so they change when it does.

Version numbers checked on 2026-09-04.

Making a two-page invoice print cleanly

HTML that looks right on screen often prints badly: a table row cut in half at the bottom of a page, a total alone on the last page, a grey background that vanishes. Print CSS fixes each of these with one rule. Here is an invoice with 40 line items, taken from a messy first print to a clean PDF.

Start with the page itself. The tool writes an @page rule for you, such as @page { size: A4 portrait; margin: 15mm; }. A4 is 210 by 297 millimetres, so 15 mm margins leave a printable area 180 mm wide. At the CSS ratio of 96 pixels to the inch, 180 mm is about 680 pixels. That is the width your layout really has on paper, which is why a design that needs 900 pixels on screen gets squeezed or cut off in print. Give the invoice a max-width in mm or a width of 100% and it fits.

Next, the table. With 40 rows it runs onto a second page. Put the heading row inside a thead element, and most browsers repeat it at the top of page 2, so the reader still knows which column is the amount. Add tr { break-inside: avoid; } so a row with a long description is not split across the page break. Browsers treat break-inside on table rows as a request rather than a promise, so check the preview of the PDF in the print dialog.

Then the totals. A short totals block often lands alone at the top of the last page. Wrap the last few rows and the totals in one element with break-inside: avoid, and the browser moves them together. If you want the terms and conditions on a page of their own, give that section break-before: page. The sample in the tool uses exactly that rule to start its last paragraph on page 2.

Last, colour. By default, browsers drop background colours when printing to save ink, so a shaded heading row prints white. This tool adds print-color-adjust: exact to the page, which asks the browser to keep them. In Chrome, also turn off Headers and footers in the print dialog, or each page gets a date and a title in its margin.

Be clear about what this tool is. It is your browser’s print to PDF, with the page set up for you. It is not a pixel-perfect renderer: the PDF is laid out for paper, not for the preview’s width, and Chrome, Firefox and Safari can each break pages a little differently. Nothing is loaded from the network, so external images, stylesheets and web fonts must be inlined first. It cannot add a table of contents, bookmarks, page numbers or a password. For those you need a dedicated PDF engine.

Frequently asked questions

Is the PDF made on a server?

No. Your browser renders the HTML and its print dialog writes the PDF. The HTML is never uploaded. This also means the result depends on your browser: Chrome, Firefox and Safari can break pages a little differently.

Why are my images or styles missing?

The preview runs in a sandbox that blocks all network requests, so anything linked by URL does not load. That includes link rel="stylesheet", img src="https://...", and web fonts. Inline the CSS in a style tag and turn images into data: URLs; the Image to Base64 tool on YappyKit does that.

Is the text in the PDF selectable?

Usually, yes. Browsers print text as text, not as a picture, so you can select and search it in the PDF. Links in the HTML usually stay clickable too, though that depends on the browser.

Will the PDF look exactly like the preview?

Close, but not exactly. The preview is a screen, and the PDF is paper of a fixed width, so text can wrap differently and the browser decides where pages break. Print-only CSS in an @media print block applies to the PDF but not to the preview.

Can I choose the PDF’s file name?

You type the file name in the save dialog. The name the browser suggests comes from the browser, not from this page, and differs between browsers.

Related tools

Your files are processed on your device and are not uploaded. You can verify this in your browser’s developer tools under the Network tab.