TailwindPHP
Plugins

Plugins

TailwindPHP ships PHP ports of the official TailwindCSS plugins and exposes a native PHP plugin API. Plugins register utilities, components, and variants; they are loaded with the @plugin directive in your input CSS. The built-in plugins are 1:1 ports of their JavaScript counterparts — same selectors and output — implemented in PHP rather than executed through Node.

Using @plugin

Reference a plugin by name with @plugin. Built-in plugins use their npm package name. Pair the directive with @import "tailwindcss/utilities.css"; so the plugin's classes are emitted into the utilities layer:

use TailwindPHP\tw;

$css = tw::generate([
    'content' => '<article class="prose prose-lg"><h1>Hello</h1><p>Content here</p></article>',
    'css' => '
        @plugin "@tailwindcss/typography";
        @import "tailwindcss/utilities.css";
    ',
]);

Multiple plugins can be loaded together, and order is independent:

@plugin "@tailwindcss/typography";
@plugin "@tailwindcss/forms";
@import "tailwindcss/utilities.css";

@plugin cannot be nested inside another at-rule (such as @media), and an unregistered plugin name throws.

Plugin options

Pass options to a plugin using CSS block syntax after the name. Keys map to the plugin's option array:

@plugin "@tailwindcss/forms" {
    strategy: "class";
}

@plugin "@tailwindcss/typography" {
    className: "markdown";
}

The @tailwindcss/forms plugin accepts strategy (base or class); @tailwindcss/typography accepts className to rename the generated prose class. See the per-plugin pages for the full option list.

Built-in plugins

PluginDescription
@tailwindcss/typographyThe prose classes — typographic defaults for rich text. See Typography.
@tailwindcss/formsResettable, stylable form controls. See Forms.

Custom plugins

Write your own plugin by implementing PluginInterface and using the methods on PluginAPI (addUtilities, matchUtilities, addComponents, addVariant, theme, and more). Register it with registerPlugin(new MyPlugin()) so the name returned by getName() resolves in a @plugin "my-plugin" directive:

use function TailwindPHP\registerPlugin;

registerPlugin(new MyCustomPlugin());

See Custom Plugins for the interface, a full example, and the complete PluginAPI method reference.

On this page