clsx

A tiny, fast utility for conditionally constructing className strings

Library
npm
v2.1.1
9,844 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
42 /100 Fair
Development Activity 0
Maintenance 20
Community 48
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
77 /100 Good
Architecture 68
Code Quality 78
Innovation 88
Learning Curve 85

clsx is a tiny (239 bytes gzipped) JavaScript utility for building className strings from a mix of strings, objects, arrays, and conditional expressions. It skips falsy values automatically, so developers can write clsx('btn', isActive && 'active', { disabled }) instead of chaining ternaries or template literals by hand.

Written by Luke Edwards as a faster, smaller drop-in replacement for the popular classnames package, clsx ships as ESM, CommonJS, and UMD builds with zero dependencies. A clsx/lite variant trims the API to string-only inputs for an even smaller footprint, and both versions are commonly paired with Tailwind CSS for conditional utility-class composition in React, Vue, Svelte, and other component frameworks.

What You Get

  • A single default export function (clsx(...inputs)) that accepts strings, numbers, objects, arrays, and nested combinations of all four
  • A clsx/lite entry point for string-only concatenation at an even smaller bundle size (140B gzipped)
  • Prebuilt ESM (dist/clsx.mjs), CommonJS (dist/clsx.js), and UMD (dist/clsx.min.js) bundles with matching TypeScript declarations
  • Zero runtime dependencies and broad compatibility down to Node 6 and IE9+ browsers

Common Use Cases

  • Toggling CSS classes based on component state, e.g. clsx('btn', { active: isActive, disabled: isDisabled })
  • Composing Tailwind CSS utility classes conditionally across React, Vue, and Svelte components
  • Merging a base class list with a className prop passed down from a parent component
  • Replacing verbose ternary or template-literal string concatenation for dynamic class names

Under The Hood

Architecture clsx is a single-file micro-library. src/index.js implements two functions: an internal recursive toVal(mix) that stringifies a single input (handling string/number, array via recursion, or object via a for...in over truthy keys), and the exported clsx(...arguments), which iterates variadic arguments, calls toVal on each truthy one, and joins the non-empty results with spaces. The lite variant (src/lite.js) drops object/array support entirely, keeping only a straight string-concatenation loop for a smaller build. The bin/index.js build script compiles both entry files into ESM, CommonJS, and minified UMD bundles under dist/, with a single ambient .d.ts/.d.mts pair shared across entry points via package.json’s exports conditions. There is no internal module graph beyond this — the runtime is well under 50 lines of code, and the package’s real “architecture” is its build/export surface (three module formats times two variants) rather than any internal layering.

Tech Stack Written in plain, ES5-compatible JavaScript with no runtime dependencies — package.json devDependencies are build/test-only (esm, terser for minification, uvu as the test runner). Types are hand-written ambient .d.ts/.d.mts files rather than generated from source, and builds are produced by a custom bin/index.js script rather than a bundler like Rollup or esbuild. The exports map targets both import and default (CJS) conditions per entry point (. and ./lite), and engines declares Node >=6 compatibility, reflecting a design goal of maximal compatibility over modern tooling.

Code Quality Tests live in test/index.js and test/lite.js using uvu + uvu/assert, covering strings, numbers, objects, arrays (including deep nesting), and edge cases like objects with push/pop keys or function arguments being ignored — a thorough suite for such a small surface area. test/classnames.js appears to benchmark parity against the classnames package it replaces. There is no TypeScript source (JS only, with a separate hand-maintained .d.ts), minimal inline comments, and terse variable naming (k, y, x, tmp) typical of size-optimized micro-libraries; readability is traded for byte count, but the logic is simple enough that this doesn’t hurt maintainability.

API Design The public API is a single variadic function accepting any mix of strings, numbers, objects, arrays, and falsy values, mirroring — and beating on file size — the popular classnames package it was designed to replace, meaning near-zero migration cost for existing users. Both a default and named clsx export are provided for import ergonomics, and the clsx/lite subpath export lets consumers opt into a smaller, string-only build without changing call sites elsewhere. The README is concise and example-driven, with runnable snippets ready to copy-paste. No configuration or setup step is required; the package is usable correctly from the first line of code.

Used by 257 apps in this directory

TypeScript
97%
MIT

NewsNow

Bookmarks Archiving

21,866

Self-hostable news aggregator with an elegant column layout, GitHub OAuth, adaptive scraping intervals, and seamless Cloudflare D1 or SQLite persistence.

View details
75
Repo Health
74
Technical
71
Dependency
Built with
TypeScript 97%
Updated 3 weeks ago
TypeScript
96%
Apache 2.0

Next AI Draw.io

AI Design Tools · Design Tools · Developer Tools

36,063

Turn natural language into professional draw.io diagrams with AI, cloud icons, and an MCP server for your IDE.

View details
78
Repo Health
80
Technical
68
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
TypeScript
88%
GPL 3.0

NoteGen

AI Assistants · Knowledge Management · Note Taking

12,848

Capture anything first, then let AI transform your scattered records into polished, structured Markdown notes with RAG-powered knowledge retrieval.

View details
86
Repo Health
74
Technical
67
Dependency
Built with
TypeScript 88%
Updated 1 weeks ago
Go
74%
Other

Notifuse

Marketing

2,223

Open-source, self-hosted alternative to Mailchimp, Brevo, and Klaviyo — send newsletters and transactional emails without per-email pricing or vendor lock-in.

View details
81
Repo Health
80
Technical
66
Dependency
Built with
Go 74%
TypeScript 23%
Updated 3 weeks ago
TypeScript
98%
Other

Novu

Developer Tools

40,084

Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.

View details
93
Repo Health
80
Technical
64
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
Java
76%
Apache 2.0

Nubase

AI Development · Low Code Platforms

624

Turn AI-written code into real apps — an open-source, self-hostable backend with Database, Auth, Storage, Memory, Functions, Assets, AI Gateway, and cron built for AI coding agents.

View details
68
Repo Health
76
Technical
74
Dependency
Built with
Java 76%
TypeScript 21%
Updated 1 months ago
Go
60%
MIT

Obot

AI Agents · Mcp

1,071

An open-source MCP platform for organizations — host MCP servers, run MCP registries, monitor usage, and build agents and chatbots on top of the Model Context Protocol from one self-hosted deployment.

View details
87
Repo Health
70
Technical
70
Dependency
Built with
Go 60%
Svelte 26%
TypeScript 13%
Updated 1 weeks ago
Go
69%
MIT

Ollama

AI Development · Developer Tools

181,830

Run Llama, Gemma, DeepSeek, and other open LLMs on your own machine with one command and an OpenAI-compatible API.

View details
90
Repo Health
85
Technical
67
Dependency
Built with
Go 69%
C 22%
Updated 1 weeks ago
TypeScript
95%
MIT

OmniRoute

AI Agents

70,824

A free, open-source AI gateway connecting Claude Code, Codex, Cursor, Cline, and Copilot to 237 AI providers (90+ free) through one endpoint, with automatic fallback and token-compression to stretch free-tier limits further.

View details
86
Repo Health
70
Technical
71
Dependency
Built with
TypeScript 95%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers