How to Convert HTML to PDF and Keep Your CSS
By Durim Hoti · Last updated
Convert HTML to PDF step by step
- Open the HTML to PDF converter.
- Paste your HTML code, or click Open .html file to load a file. The PDF gets the file's name.
- Check the PDF preview on the right. Dashed lines mark where pages end.
- Choose page size (A4 or Letter), orientation and margins, and keep Background colors and images ticked if the design uses colored areas.
- Click Convert to PDF, read any warnings, then click Download PDF.
Example: an invoice with a colored header
This invoice uses a Google Font, a blue header and a logo stored next to the file:
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap">
<style>
body { font-family: Inter, sans-serif; margin: 0; }
header { background: #1d4ed8; color: #fff; padding: 24px; }
</style>
<header><h1>Invoice 1042</h1></header>
<main style="padding: 24px">
<img src="logo.png" alt="Logo" width="80" height="40">
<table>
<tr><td>Website design</td><td>$1,200</td></tr>
<tr><td>Hosting, 12 months</td><td>$96</td></tr>
</table>
</main>
What we saw when converting it on November 28, 2026 (A4, normal margins):
- The PDF has one page.
- With Background colors and images on, the header in the PDF is blue (we measured rgb(29, 78, 215)); with the option off, it is white.
- The Google Font loaded without a warning. The logo did not, and the converter showed: An image could not be loaded, so it was left empty.
The logo fails for the same reason it would in any online tool: the converter only has the HTML, not the folder with logo.png.
What to check so the CSS survives
- Backgrounds: keep the background option ticked. Without it, background colors and images are dropped, which saves ink when printing.
- Fonts: link web fonts with a full URL from a service that allows cross-origin use, such as Google Fonts. If a font can't be loaded, the converter warns that a font could not be included.
- Images: use full
https://URLs or embed them as data URLs. Relative paths don't work. - Screen styles: the converter uses your normal (screen) CSS, not
@media printrules, and takes page size and margins from its own settings. - Page breaks:
break-before: pageandbreak-inside: avoidwork; table headers aren't repeated on every page. The details are in our tested article CSS page breaks in HTML to PDF.
Common problems
Colored backgrounds are white in the PDF
The Background colors and images option is off. Tick it and convert again.
An image is empty
The converter couldn't load it and says so in its warnings. Relative paths never work; images on other websites only load when that site allows cross-origin access. An image embedded as a data URL is part of the HTML itself and needs no download; you can create one with the image to Base64 converter.
The text looks smaller than expected
Something on the page is wider than the PDF page, so the whole document was scaled down to fit; the converter mentions this in its warnings. Look for fixed widths, wide tables or long unbroken lines, or switch to landscape.
Content added by JavaScript is missing
Scripts don't run during conversion. Render the final HTML first, for example in the HTML compiler, and convert that.
When to use the browser's print dialog instead
For vector text and for fonts or images from sites that block cross-origin access, use Print / Save as PDF, which opens your browser's print dialog. The comparison table on the converter page lists when each way fits. Coming from Word? First convert the Word document to HTML.
FAQ
- Is there a page or size limit?
- A PDF can have up to 100 pages, and an uploaded HTML file can be up to 5 MB. There is no limit on how many PDFs you create.
- Is my HTML uploaded to a server?
- No. The page is rendered and turned into a PDF in your browser. Only resources your HTML links to, such as fonts or images on other websites, are loaded from those websites.
- Can I convert a web page by its URL?
- No. The converter works with HTML code or an .html file. Save the page from your browser as an HTML file, or copy its source, and open that in the converter.
- Are links in the PDF clickable?
- Yes. Links stay clickable, and text stays selectable and searchable for Latin-script languages. Each page is stored as an image with an invisible text layer, so the text is not vector text.
- Why are the page breaks different from my browser's print preview?
- The converter and the browser's print dialog handle some page-break rules differently, for example repeated table headers and orphans and widows. Our test article on CSS page breaks shows the differences with examples.
Try it and keep reading
- Open the HTML to PDF converterConvert HTML code or files to a downloadable PDF.
- How to Convert a Word Document to Clean HTMLTurn a .docx file into clean HTML and know what is kept, what is dropped and why.
- How to Open an HTML File on Any DeviceSee the page or the code of an .html file on a computer or a phone, and fix missing images.