Guides › mPDF › Supported CSS in mPDF

Supported CSS in mPDF

Written for mPDF 8.2 on PHP 8.1+. Updated 2 November 2026.

mPDF implements a solid part of CSS 2.1, some CSS 3 and the paged-media rules print needs. It does not try to match a modern browser. Knowing where the line is saves hours.

Works well

  • Text: font-family, font-size, font-weight, font-style, color, line-height, letter-spacing, word-spacing, text-align (including justify), text-indent, text-transform, text-decoration, text-shadow.
  • Box model: margin, padding, border (all styles), border-radius, width, height, box-shadow on block elements.
  • Colour: names, hex, rgb(), rgba(), CMYK with cmyk(), and opacity.
  • Backgrounds: colours, images, linear-gradient() and radial-gradient() (see backgrounds and borders).
  • Paged media: @page with size, margins, headers and footers, plus named pages, page-break-before, page-break-after and, on tables, page-break-inside: avoid.
  • Positioning: float on block elements, and position: absolute or fixed for blocks placed relative to the page, which suits letterheads and stamps.
  • Selectors: element, class, id and descendant selectors, plus :first-child and :nth-child(odd|even) on table rows.

Not supported, and what to do instead

Not supported Instead
display: flex and grid A table with fixed column widths, or floated blocks with set widths.
display: inline-block A table cell, or a float.
CSS custom properties (var(--x)) Generate the values in PHP, or run a preprocessor first.
@font-face Register the font in the fontdata config (how).
calc(), vw/vh units Fixed sizes in mm, pt or %.
Complex selectors (~, +, most pseudo-classes) Add a class to the element.
transform on ordinary blocks rotate on tables, or images rotated beforehand.

Units

On paper, use mm or pt. Pixels are converted at the dpi setting (96 by default), which is fine for borders but unpredictable for page-sized boxes. Percentages work against the containing block.

A quick test

When a style doesn’t apply, isolate it in a ten-line document. If it fails there too, it isn’t supported, and a table-based layout is usually the fastest way around it. The examples gallery shows layouts that render the same in mPDF and in browsers.