Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Tailwind Merge Php

Tailwind Merge Php Laravel Package

gehrisandro/tailwind-merge-php

Merge Tailwind CSS class strings in PHP with automatic conflict resolution (later classes win). PHP port of dcastil/tailwind-merge, compatible with Tailwind v3.0–v3.4 and PHP 8.1+. Create instances and customize configuration as needed.

View on GitHub
Deep Wiki
Context7

TailwindMerge for PHP lets you merge multiple Tailwind CSS class strings while automatically resolving class conflicts (later classes win). It’s a PHP port of the popular tailwind-merge project and supports Tailwind v3.0–v3.4 on PHP 8.1+.

Use TailwindMerge::instance()->merge(...) for quick merges, or create a custom instance via the factory to tweak behavior.

  • Conflict-aware merging that removes overridden utilities
  • Works with multiple class inputs and preserves order
  • Configurable via a factory for custom rules
  • Built-in caching support for faster repeated merges
  • Framework-agnostic (with a dedicated Laravel companion package)
Frequently asked questions about Tailwind Merge Php
How do I merge Tailwind CSS classes in Laravel using this package?
Use `TailwindMerge::instance()->merge('class1', 'class2')` to merge classes, where later classes override earlier ones. For example, merging `text-red-500` and `text-blue-500` returns `text-blue-500`. Works seamlessly in Blade templates, Livewire components, or API responses.
Does this package support Laravel’s Blade templating?
Yes, it’s framework-agnostic but integrates perfectly with Laravel Blade. Use it directly in Blade files or pass merged classes to Livewire components. For deeper integration, pair it with the companion package `tailwind-merge-laravel`.
What Laravel and PHP versions are supported?
This package requires **PHP 8.1+** and works with Laravel 8.x–10.x. It’s compatible with Tailwind CSS v3.0–v3.4. If you’re using Laravel <8.0 or Tailwind v2.x/v4.x, you may need custom configuration or a fork.
How do I customize conflict resolution for my Tailwind config?
Use the factory method to create a custom instance: `TailwindMerge::factory()->withConfiguration(['classGroups' => [...]])`. This lets you define custom rules for non-standard Tailwind setups, like renamed classes or arbitrary values.
Can I cache merged results for performance?
Yes, the package supports PSR-16 caching (e.g., Laravel’s cache system). Enable it via `TailwindMerge::factory()->withCache($cache)` to store merged results, reducing runtime overhead for repeated merges in high-traffic applications.
Will this break if I use non-Tailwind classes (e.g., custom CSS)?
No, the package gracefully handles non-Tailwind classes by ignoring them during merging. Only Tailwind utilities are processed, so classes like `my-custom-class` remain untouched in the output.
How does this compare to client-side merging (e.g., JavaScript tailwind-merge)?
Server-side merging (PHP) is ideal for Laravel apps where classes are generated dynamically in Blade, Livewire, or APIs. Client-side merging (JS) is better for interactive UIs but adds bundle size. This package avoids client-side dependencies entirely.
Does it support Tailwind’s dark mode, hover states, or arbitrary values?
Yes, it handles dark mode classes (e.g., `dark:bg-gray-800`), hover/focus states (e.g., `hover:text-blue-600`), and arbitrary values (e.g., `[&>*:nth-child(2)]:text-red-500`). Test edge cases in your setup to ensure compatibility with custom configurations.
Is there a Laravel-specific wrapper for easier integration?
Yes, the companion package [`tailwind-merge-laravel`](https://github.com/gehrisandro/tailwind-merge-laravel) provides Laravel-specific helpers, like Blade directives and Livewire integration. Install it via `composer require gehrisandro/tailwind-merge-laravel`.
How do I handle conflicts with custom Tailwind configurations (e.g., renamed classes)?
If your `tailwind.config.js` uses custom class names or modified utilities, define them in `classGroups` via the factory. For example, `->withConfiguration(['classGroups' => ['custom' => ['.my-bg' => 'bg']]])` maps custom classes to Tailwind’s rules.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport