
Tailwind CSS doesn’t automatically process .php files unless explicitly configured—update the content array in tailwind.config.js to include "*.php" glob patterns so Tailwind scans and purges classes from your PHP templates.
tailwind css doesn’t automatically process `.php` files unless explicitly configured—update the `content` array in `tailwind.config.js` to include `"*.php"` glob patterns so tailwind scans and purges classes from your php templates.
To use Tailwind CSS seamlessly with PHP files (e.g., index.php, header.php, or Laravel Blade-like templates), you must configure Tailwind’s content discovery to recognize .php extensions. By default, the content field in tailwind.config.js only includes html and js files—so PHP markup containing utility classes like text-blue-500 or flex gap-4 gets ignored during build or JIT compilation, resulting in missing styles.
✅ Solution: Update your tailwind.config.js to include php in the file extension list:
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/**/*.{html,js,php}", // ← Added 'php' here
"./public/**/*.php", // ← Optional: include public/ if using standalone PHP
"./templates/**/*.php", // ← Adjust path as needed for your project structure
],
theme: {
extend: {},
},
plugins: [],
}
? Important notes:
- Use glob patterns, not file extensions alone — e.g.,
"./*.php"matches top-level PHP files;"./src/**/*.php"recursively matches all.phpfiles undersrc/. - After updating the config, rebuild your CSS (e.g., run
npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch) — changes won’t take effect until Tailwind re-scans content. - Ensure your PHP files contain actual Tailwind class names (e.g.,
<div class="bg-gray-100 p-6 rounded-lg">) — no special PHP syntax is required; treat <code>.phpfiles just like.htmlwhen writing classes. - Avoid relying on
@layeror arbitrary values only inside PHP files — always define custom styles in CSS ortheme.extendfor consistency. - Forgetting to restart the Tailwind CLI watcher after config changes.
- Using outdated glob syntax (e.g.,
**/*.phpwithout braces) — modern Tailwind v3+ requires brace expansion like{html,js,php}. - Placing PHP files outside declared
contentpaths — double-check your directory structure matches the glob.
⚠️ Common pitfalls:
Once configured correctly, Tailwind will detect classes in <?php echo '<div class="text-center font-bold">Hello











