Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

This module provides a Twig extension to automatically merge and optimize Tailwind CSS class lists, resolving conflicts to ensure a clean output. It can output classes as a string or an array, making it easy to use with Drupal's theming system.

Introduction

Tailwind Merge Classes is a Drupal module for users working with Tailwind CSS in a component-based syntax. It provides a Twig extension that merges multiple Tailwind CSS classes, resolves conflicts automatically, and ensures a clean, optimized class list. For example, tw_merge(['p-2', 'p-4']) intelligently keeps only the last one, 'p-4'. Array output is also supported via tw_merge with as='array' (or the legacy tw_merge_as_array function), which is recommended when used with Drupal's addClass(). If you are interested in more details, this video explains the original JavaScript utility tailwind-merge that this module's logic is based on.

Usage

Get started quickly by checking out dedicated guides:

Version Support

  • Module version 1.x: Compatible only with Tailwind CSS 3.x
  • Module version 2.x: Compatible only with Tailwind CSS 4.x

Post-Installation

Once you install the Tailwind Merge Classes module, there's no need for extra configuration or managing content types. Simply enable the module and start using it in your Twig files.

Third-Party Libraries

This module depends on different PHP packages to handle merging of Tailwind CSS classes for each Tailwind version.

Both PHP packages require PHP 8.1 and above.

Activity

Total releases
10
First release
Jan 2025
Latest release
1 month ago
Releases (12 mo)
7 ▲ from 3
Maintenance
Active

Release Timeline

Releases

Version Type Release date
2.2.0 Stable May 24, 2026
1.2.0 Stable May 24, 2026
2.1.0 Stable Jan 18, 2026
1.1.0 Stable Jan 18, 2026
2.0.0 Stable Dec 31, 2025
1.0.1 Stable Dec 28, 2025
1.0.0 Stable Dec 27, 2025
1.0.0-beta2 Pre-release Jun 19, 2025
1.0.0-beta1 Pre-release Jan 22, 2025
1.0.x-dev Dev Jan 20, 2025