Guides › mPDF › Supported HTML in mPDF

Supported HTML in mPDF

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

mPDF reads ordinary HTML, but it is a print layout engine, not a browser. It understands the document structure well and renders a sensible subset of CSS on top. Writing HTML the way you would for an email (simple blocks and tables) gives the most predictable results.

Standard tags that work well

  • Blocks: div, p, h1–h6, blockquote, pre, address, hr, and the HTML5 sectioning tags such as header and section.
  • Lists: ul, ol (with type and start), li, dl/dt/dd. Nested lists are fine.
  • Inline: span, a (links stay clickable in the PDF), b/strong, i/em, u, s, sup, sub, small, code, br.
  • Images: img, including SVG files and data URIs (see images).
  • Forms: inputs, selects and textareas are drawn as static boxes. Set useActiveForms to make them fillable PDF fields.

Anything mPDF doesn’t know is treated like a span, and script is ignored.

Tables

Tables are mPDF’s most dependable layout tool, which is why invoices and reports are usually built from them.

  • colspan, rowspan, thead, tbody and tfoot are supported. A thead row repeats at the top of each page when a table breaks across pages.
  • By default, a table too wide for the page is shrunk to fit (up to a limit). Set shrink_tables_to_fit to change this.
  • <table autosize="1"> lets mPDF scale a table so it fits on one page, and <table rotate="90"> turns a wide table sideways.
  • Nested tables work, but each level adds layout cost. Prefer one level where you can.

See the price list example for a long table with a repeating header.

mPDF-only tags

mPDF adds its own tags for things HTML has no words for:

Tag Purpose
<pagebreak /> Start a new page, optionally changing orientation or margins. More.
<columns column-count="2" /> Switch to multi-column text, and back with column-count="1".
<htmlpageheader>, <htmlpagefooter> Define named headers and footers. More.
<barcode /> Draw a barcode or QR code. More.
<tocpagebreak />, <tocentry /> Build a table of contents.
<bookmark content="…" /> Add an entry to the PDF’s bookmark panel.
<watermarktext content="DRAFT" /> Watermark the page (also SetWatermarkText()).

Writing HTML that converts cleanly

  1. Use tables for side-by-side layout. Flexbox and grid are not supported (see supported CSS).
  2. Put CSS in a <style> block or a separate WriteHTML($css, \Mpdf\HTMLParserMode::HEADER_CSS) call.
  3. Give images explicit widths in mm or px so layout doesn’t depend on the source file’s dpi.
  4. Test with real data. Long names and 200-row tables reveal problems that sample data hides.