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

LimitationWorkaround
No display: flex or gridLay out columns with a table, or floats with fixed widths. Tables are the most predictable.
inline-block is largely ignoredUse table cells for side-by-side boxes.
Floats only on block elements, with limits on nestingKeep floated layouts one level deep, or switch to a table.
Vertical centring is awkwardUse a table cell with vertical-align: middle.
Very long or deeply nested tables are slowFlatten the structure and use simpleTables (see performance).

CSS features

LimitationWorkaround
No CSS variables, calc() or viewport unitsCompute values in PHP, or run a CSS preprocessor first.
No @font-faceRegister 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 blocksRotate tables with rotate="90", and rotate images before embedding them.
background-size is replaced by its own propertyUse background-image-resize (values).

Content

LimitationWorkaround
JavaScript never runsRender 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 fullySimplify the SVG, or export it to PNG at print resolution.
Remote images and stylesheets depend on network access from the serverUse local files or imageVars (see images).
Built-in encryption is not AES-256Encrypt 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.