TwMerge 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package TwMerge --version 1.0.1
                    
NuGet\Install-Package TwMerge -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TwMerge" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TwMerge" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="TwMerge" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TwMerge --version 1.0.1
                    
#r "nuget: TwMerge, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TwMerge@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TwMerge&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=TwMerge&version=1.0.1
                    
Install as a Cake Tool

TailwindMerge Logo

TailwindMerge 🍃

NuGet Version

A high-performance .NET library for merging Tailwind CSS class names with full conflict resolution, deduplication, and support for all major Tailwind v4 utilities, responsive breakpoints, and modifiers.

Features

  • Tailwind v4 Support: Handles all major class groups, including text, font, spacing, layout, color, and more
  • Conflict Resolution: Automatically removes conflicting or duplicate classes, keeping only the last in each group
  • Responsive & Modifier Aware: Correctly merges classes with responsive prefixes (sm:, md:, etc.) and modifiers (hover:, focus:, dark:, etc.)
  • Arbitrary Value Support: Handles arbitrary values and custom properties (e.g., w-[32px])
  • High Performance: Zero-allocation merging with LRU caching for repeated merges
  • Customizable: Extend or override class groups and conflict rules via configuration

Installation

dotnet add package TailwindMerge

Quick Start

  1. Add TailwindMerge to your project and create a merger instance:
using TailwindMerge;
 
// Create instance with default config
var twMerge = new TwMerge(); 
  1. Merge Tailwind class names:
// merged == "w-4 hover:w-4 text-blue-500"
var merged = twMerge.Merge("w-3", "w-4", "hover:w-3", "hover:w-4", "text-red-500", "text-blue-500"); 

Core Components

TwMerge

The main entry point for merging Tailwind CSS class names, resolving conflicts and removing duplicates.

TwConfig

Configures class groups, conflict rules, theme, and other options. Use TwConfig.Default() for standard Tailwind v4 support, or customize as needed.

Configuration Options

You can customize merging behavior by creating a custom TwConfig:

var config = new TwConfig()
    .CacheSize(1000)
    .ClassGroups(customClassGroups)
    .Separator(":")
    .Prefix("tw-")
    .ConflictingClassGroups(customConflicts);

var twMerge = new TwMerge(config);

Example Usage

var twMerge = new TwMerge();
var result = twMerge.Merge( "sm:text-xs", "sm:text-lg", "md:text-base", "md:text-xl", "p-2", "p-4", "hover:bg-red-500", "hover:bg-blue-500" ); // result == "sm:text-lg md:text-xl p-4 hover:bg-blue-500"

Requirements

  • .NET 9.0 or higher

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.7 359 5/29/2025
1.0.4 172 5/29/2025
1.0.2 139 5/29/2025
1.0.1 138 5/29/2025
1.0.1-g34e451f73e 137 5/29/2025