@formepdf/tailwind lets you style Forme components with Tailwind CSS utility classes instead of writing style objects by hand.
The tw() function returns a plain FormeStyle object. You can spread it, merge it, or pass it directly to style.
className is not supported. Forme components don’t have a DOM, so there’s no CSS cascade. Use tw() to convert classes into a style object and pass it to the style prop.
How it works
tw() parses a space-separated string of Tailwind classes and returns the equivalent Forme style object. Unknown classes are silently ignored. When classes conflict, the last one wins.
You can merge with custom styles using spread:
Spacing
Tailwind spacing values are multiplied by 4 (matching Tailwind’s default 4px scale). p-4 = 16pt, m-2 = 8pt, etc.
Negative values
Prefix any spacing or positional class with - to negate:
Typography
Colors
The full Tailwind color palette is supported: slate, gray, zinc, neutral, stone, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose. Each with shades 50-950.
Layout
Dimensions
Fraction widths
Use fractions for percentage-based sizing:
Grid
Borders
Positioning
Opacity
Arbitrary values
Use bracket syntax for exact values that don’t map to the Tailwind scale:
Colors work too:
All spacing prefixes support arbitrary values: px-[10], mt-[8], mx-[16], min-w-[100], max-h-[300], etc.
Real-world examples
Data grid
Badge
What’s not supported
These Tailwind features don’t apply to PDF rendering and are intentionally excluded:
- Responsive prefixes (
sm:, md:, lg:) — PDFs have no viewport breakpoints
- State variants (
hover:, focus:, active:) — PDFs are not interactive
- Dark mode (
dark:) — no media queries in PDF
z-index, aspect-ratio, object-fit — not supported by the Forme engine
TypeScript
tw() returns a FormeStyle type that’s compatible with Forme component style props: