TailwindPHP

CLI

./vendor/bin/tailwindphp is a 1:1 port of @tailwindcss/cli — same options, same behavior, no Node.js required. After composer require tailwindphp/tailwindphp, the binary is linked into vendor/bin/.

If you only need CSS at runtime from PHP, use the API instead — the CLI is for build-step workflows that write a stylesheet to disk.

Quick start

# Build CSS from an input file
./vendor/bin/tailwindphp -i ./src/app.css -o ./dist/styles.css

# Watch for changes and rebuild
./vendor/bin/tailwindphp -i ./src/app.css -o ./dist/styles.css --watch

# Build minified for production
./vendor/bin/tailwindphp -i ./src/app.css -o ./dist/styles.css --minify

Options

tailwindphp [--input input.css] [--output output.css] [--watch] [options…]
OptionDescriptionDefault
-i, --inputInput CSS file@import "tailwindcss"
-o, --outputOutput file- (stdout)
-w, --watchWatch for changes and rebuild as needed
-m, --minifyOptimize and minify the output
--optimizeOptimize the output without minifying
--cwdThe current working directory.
-h, --helpDisplay usage information

When --output is - (the default), the compiled CSS is written to stdout, so you can pipe it elsewhere.

Input CSS

Create an app.css with your Tailwind import and a @source directive telling TailwindPHP where to scan for classes:

@import "tailwindcss";
@source "./templates"; /* Directory to scan for classes */

@source accepts directories, glob patterns, and multiple entries:

@import "tailwindcss";
@source "./templates";           /* a directory */
@source "./src/**/*.php";         /* a glob */
@source "./resources/views";      /* add as many as you need */

See @source for the full directive reference, including not and inline() forms.

Examples

# Build from CSS with a @source directive
tailwindphp -i ./src/app.css -o ./dist/styles.css

# Build minified for production
tailwindphp -i ./src/app.css -o ./dist/styles.css -m

# Watch mode with minification
tailwindphp -i ./src/app.css -o ./dist/styles.css -w -m

# Run against a different working directory
tailwindphp -i app.css -o dist/styles.css --cwd=/path/to/project

The CLI creates the output directory if it does not exist, and exits with an error if the input file is missing or the input and output paths are identical.

Global installation

Install globally to use tailwindphp from anywhere:

composer global require tailwindphp/tailwindphp

# Now available globally
tailwindphp -i ./src/app.css -o ./dist/styles.css

See Getting Started for project setup and the API for runtime CSS generation from PHP.

On this page