A utility to efficiently merge Tailwind CSS classes in C# without style conflicts.
- Supports Tailwind v3.4
- Thread-safe LRU caching
.NET SDK | Support |
---|---|
.NET 8 | ✔️ |
Register the service in the DI container:
// Program.cs
using TailwindMerge.Extensions;
var builder = WebApplication.CreateBuilder( args );
// Add TailwindMerge to the container
builder.Services.AddTailwindMerge();
Inject the service into component using one of the following approaches:
@* Page.razor *@
@inject TwMerge TwMerge
@TwMerge.Merge("px-2 py-1 bg-red hover:bg-dark-red", "p-3 bg-[#B91C1C]")
@* → "hover:bg-dark-red p-3 bg-[#B91C1C]" *@
// Page.razor.cs
[Inject] private TwMerge TwMerge {get; set; } = default!;
TwMerge.Merge("px-2 py-1 bg-red hover:bg-dark-red", "p-3 bg-[#B91C1C]")
// → "hover:bg-dark-red p-3 bg-[#B91C1C]"
Contributions are always welcome!
See CONTRIBUTING.md for ways to get started. Please adhere to this project's CODE_OF_CONDUCT.
This project is a C# adaptation of tailwind-merge originally developed by dcastil.