mPDF › Limitations
mPDF limitations and workarounds
mPDF is a PHP typesetting engine, not a web browser. That makes it fast to deploy (no headless Chrome to install) and good at print features like headers, footers and page numbering, but it doesn’t render everything a browser does. Here is what to expect and how to work around it.
Layout
| Limitation | Workaround |
|---|---|
No display: flex or grid | Lay out columns with a table, or floats with fixed widths. Tables are the most predictable. |
inline-block is largely ignored | Use table cells for side-by-side boxes. |
| Floats only on block elements, with limits on nesting | Keep floated layouts one level deep, or switch to a table. |
| Vertical centring is awkward | Use a table cell with vertical-align: middle. |
| Very long or deeply nested tables are slow | Flatten the structure and use simpleTables (see performance). |
CSS features
| Limitation | Workaround |
|---|---|
No CSS variables, calc() or viewport units | Compute values in PHP, or run a CSS preprocessor first. |
No @font-face | Register fonts through the fontdata configuration (how). |
| Limited selectors (no sibling combinators, few pseudo-classes) | Add classes to the elements you need to style. |
transform doesn’t apply to ordinary blocks | Rotate tables with rotate="90", and rotate images before embedding them. |
background-size is replaced by its own property | Use background-image-resize (values). |
Content
| Limitation | Workaround |
|---|---|
| JavaScript never runs | Render charts and dynamic content on the server, as SVG or PNG, before passing the HTML to mPDF. |
| Complex SVG (filters, masks, embedded CSS) may not render fully | Simplify the SVG, or export it to PNG at print resolution. |
| Remote images and stylesheets depend on network access from the server | Use local files or imageVars (see images). |
| Built-in encryption is not AES-256 | Encrypt the finished file with a dedicated tool (see password protection). |
When to use something else
If your documents depend on modern browser layout, such as a design system built on flexbox and grid or charts drawn with JavaScript, a headless browser renders them exactly as on screen. The trade-off is running Chrome on your server. For a one-off document, our in-browser HTML to PDF tool uses your own browser’s engine and needs no server at all.
For everything else (invoices, statements, tickets, letters, certificates, reports), mPDF’s limits rarely matter once layouts are built with tables. See the examples gallery for templates that respect them.