Black Friday: 50% off every paid plan with code BF50. Ends 5 December.

See prices

Free tool

HTML to PDF, with your CSS kept.

Paste HTML or open an .html file, such as an email template, an invoice, a report or a page you saved, and save it as a PDF. Your own browser draws it, so styles, web fonts and colours come out the way they look on screen, and the text stays selectable. Choose the paper size and margins, add page numbers or a header, and drop in the pictures that go with the file. A page wider than the paper is shrunk to fit.

Need a custom tool, app or website? Contact us 
HTML
Preview at paper width

A print window opens. Choose "Save as PDF" as the destination, then Save.

Paper

Only for HTML you trust. Scripts are off so that code from elsewhere cannot run on this page.

Page numbers and the header are printed by Chrome and Edge. In other browsers, turn on headers and footers in the print window instead. Your settings are kept for next time, except scripts, which start off.

The HTML is shown and printed by your browser. It is never uploaded.

Tips

For a PDF that looks right.

01 / Pictures

Full addresses load

Pictures with full web addresses load as usual. For pictures saved next to the file, drop them in with it.

02 / Breaks

New page where you want

Add style="break-before: page" to any element to start a new page there.

03 / Print styles

@media print

Rules inside @media print in your CSS apply to the PDF only, for example to hide a menu or buttons.

Guide

How to convert HTML to PDF, and keep your CSS.

To convert HTML to PDF, you have a browser draw the page at paper size and save it through its print engine as a PDF. This tool does that for HTML you paste or an .html file you open: it shows the page in a preview at the paper's width, adds the page size and margins you pick, then opens your browser's print window so you can save it. Because your own browser draws it, your CSS, web fonts and colours come out as they look on screen, and the text stays real text you can select.

How to convert HTML to PDF

  1. Paste your HTML into the box, or drop an .html file on the area below it. Click Example to try it with a sample invoice.
  2. If the file uses pictures, stylesheets or fonts saved next to it, drop them in the same go as the HTML file. They are matched by file name.
  3. Pick the paper Size, the Direction and the Margins. The preview redraws at the new width. Add Page numbers or a Header on every page if you want them.
  4. Leave Keep background colours and pictures ticked if your design has coloured blocks or a background image.
  5. Click Save as PDF. Your browser's print window opens.
  6. Set the destination to Save as PDF, then click Save and choose where the file goes.

In Chrome and Edge, the destination menu is at the top of the print window. In Safari, open the PDF menu at the bottom of the print window and choose Save as PDF. In Firefox, the destination is called Save to PDF. The name the browser suggests for the file comes from the <title> of your HTML, or from the file name when there is no title.

Why the preview is narrower than your screen

The page is laid out at the width of the paper less the margins, the same width the PDF will have. CSS counts 96 pixels to the inch, which is 25.4 mm, so you can work out the width your design gets:

Paper and marginsWidth for your contentIn CSS pixels
A4 portrait, Normal (15 mm)210 minus 30 = 180 mmabout 680 px
US Letter portrait, Normal215.9 minus 30 = 185.9 mmabout 703 px
A4 portrait, None210 mmabout 794 px
A4 landscape, Normal297 minus 30 = 267 mmabout 1,009 px
A3 landscape, Normal420 minus 30 = 390 mmabout 1,474 px

The sum for the first row: 180 divided by 25.4 is 7.09 inches, and 7.09 times 96 is about 680. If your page was designed for a desktop screen, say 1,200 pixels wide, its media queries may switch it to a narrower layout at 680. That is often what you want on paper. If not, pick Landscape or A3, or set Margins to None to win back the space.

Some pages have a fixed width that is wider than the paper, such as a wide table or a layout set to 1,200 pixels. With Shrink a wide page to fit the paper ticked, the whole page is scaled down until it fits, and the message says by how much. Untick it to keep the size, in which case the right side is cut off.

Page numbers and a header

Page numbers (1 / 12 or Page 1 of 12) go at the foot of every page, and a header line at the top. Both sit in the page margin, so the margin is made at least 10 mm when either is on. They use CSS page margin boxes, which Chrome and Edge print; other browsers leave them out, and there you can turn on Headers and footers in the print window instead. When you use these, turn the print window's own Headers and footers off, or you get both.

CSS that makes a better PDF

  • Start a new page. Add style="break-before: page" to a heading or a section to begin it at the top of a fresh page.
  • Hide things on paper. Put rules inside @media print { } in your CSS. They apply only to the PDF, so you can hide a menu, buttons or a cookie bar with display: none.
  • Keep blocks whole. Do not split pictures and tables across pages adds break-inside: avoid to pictures, tables, code blocks and quotes, and keeps headings with the text below them. A table taller than one page still has to split.
  • Use real units for print. Sizes in mm, cm or pt come out at that size on paper, which helps for labels, tickets and letterheads.

What works and what does not

In your HTMLIn the PDF
CSS in a style tag or inlineKept
A stylesheet saved as a separate fileKept if you drop it in with the HTML file
Pictures with a full web addressLoad as usual
Pictures saved next to the fileKept if you drop them in with it
Web fonts from a font serviceLoad as usual when you are online
LinksUsually stay clickable, depending on the browser
JavaScriptOff, unless you tick Run the page's scripts

Scripts are off by default because pasted code could come from anywhere. Tick Run the page's scripts only for HTML you wrote or trust, such as a report that draws its charts with JavaScript.

Common problems

  • Pictures are missing. The HTML points to files on your computer by a relative path. Drop the pictures in together with the HTML file. The message under the drop area says how many of the dropped files the page uses.
  • Backgrounds are white. Browsers leave backgrounds out when printing unless told not to. Keep the box ticked, and if they are still missing, turn on Background graphics in the print window's settings.
  • Extra headers and footers. Some browsers add the date and the address to each page. Untick Headers and footers in the print window, and use Page numbers and Header on this page instead.
  • The right side is cut off. The page is wider than the paper. Tick Shrink a wide page to fit the paper, or pick Landscape.
  • A website address does not work. This page cannot fetch pages from other sites. Open the site in a tab and print it to PDF there, or save it as HTML and drop it here.

Writing in Markdown instead? Markdown to PDF makes the file directly with no print window. For a plain letter or notes, use text to PDF, and shrink a heavy result with compress PDF.

Questions

Good to know.

Can I convert a website address to PDF?

Not here. Web pages on other sites cannot be read from this page without a server in between, and this tool has none. Open the site in your browser and use File, Print, Save as PDF, or save the page as HTML and drop it here.

Why is the background missing in my PDF?

Browsers leave out backgrounds when printing unless told otherwise. "Keep background colours and pictures" tells them to keep them; if they are still missing, tick "Background graphics" under More settings in the print window.

Is the text in the PDF selectable?

Yes. The browser writes the text as text with its fonts, the same as printing any web page to PDF.

The print window does not open.

Some browsers block printing from inside a frame or a pop-up blocker steps in. Allow pop-ups for this site, or save the HTML as a file, open it in a browser tab and print it from there.

Can I turn Markdown into PDF?

Yes, use Markdown to PDF, which makes the PDF directly without a print window.

How do I convert an HTML file to PDF without software?

Drop the file on this page and click Save as PDF. Your browser's own print window saves it, so there is nothing to install and no account.

How do I stop a table or picture being cut in half?

Keep Do not split pictures and tables across pages ticked. Anything shorter than a page then moves whole to the next page. For a manual break, add break-before: page to the element.

Can I convert an HTML email template to PDF?

Yes. Paste the template's code, check the preview, and save. Email templates often use tables and inline styles, which come out as they look in the preview.

Can I add page numbers to the PDF?

Yes. Pick 1 / 12 or Page 1 of 12 under Page numbers. Chrome and Edge print them at the foot of each page. You can also add a short header line, such as a title or a date.

Why does my PDF have a blank last page?

Something on the page runs a little past the end of the last sheet, often a bottom margin or padding. Reduce the bottom margin or padding of the last element, or set Margins to Narrow.

Can I choose Letter size or landscape?

Yes. Pick A4, US Letter, US Legal, A3 or A5, or let the page set its own size, and choose Portrait or Landscape before you save.

Listed on

Listed on JustMacAppsMotionShine on Mac App IndexMotionShine on ScrollLaunchMotionShine featured on StartupBaseFeatured on FazierFeatured on Twelve ToolsMotionShine - Featured on Smol Launch