Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
tailwind-merge
Advanced tools
The tailwind-merge npm package is a utility for combining and deduplicating Tailwind CSS classes. It helps developers to programmatically merge class strings while avoiding conflicts and redundancies, ensuring the final class string is optimized for use.
Merging Tailwind CSS classes
This feature allows you to merge multiple class strings into one, automatically resolving conflicts by using the last occurrence of a conflicting class.
"twMerge('p-4 font-bold', 'p-2 text-center') // 'p-2 font-bold text-center'"
Removing Tailwind CSS classes
This feature enables you to remove specific classes from a string by prefixing the class with a minus sign.
"twMerge('p-4 font-bold', '-p-4') // 'font-bold'"
Handling arbitrary values
Tailwind-merge can handle arbitrary values in class names, allowing you to merge classes with custom values effectively.
"twMerge('p-[30px]', 'p-4') // 'p-4'"
Handling variants and groups
The package can also manage Tailwind's variants and groups, ensuring that the correct specificity is maintained when merging classes with variants.
"twMerge('hover:bg-black', 'hover:bg-white') // 'hover:bg-white'"
The classnames package is a popular utility for conditionally joining class names together. It's not Tailwind-specific, but it's often used in projects to manage dynamic class strings. Unlike tailwind-merge, it does not deduplicate or resolve conflicts specific to Tailwind CSS.
clsx is an alternative to classnames with a similar API and is used for constructing class strings conditionally. Like classnames, it does not offer Tailwind-specific deduplication or conflict resolution.
Utility function to efficiently merge Tailwind CSS classes in JS without style conflicts.
import { twMerge } from 'tailwind-merge'
twMerge('px-2 py-1 bg-red hover:bg-dark-red', 'p-3 bg-[#B91C1C]')
// → 'hover:bg-dark-red p-3 bg-[#B91C1C]'
FAQs
Merge Tailwind CSS classes without style conflicts
The npm package tailwind-merge receives a total of 3,239,184 weekly downloads. As such, tailwind-merge popularity was classified as popular.
We found that tailwind-merge demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.