Skip to content
Package42 repository health

clsx

A tiny, fast utility for conditionally constructing className strings

Library npmv2.1.19,847 stars MIT License
npm install clsx
View source

Repository health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
Fair
  • Development activity0
  • Maintenance20
  • Community48
  • Maturity60
  • Momentum40

Technical analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
Good
  • Architecture68
  • Code quality78
  • Innovation88
  • Learning curve85

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 252 apps in this directory

Every app whose dependencies include clsx, nine to a page.

Showing 252 apps
TypeScript 76%AGPL 3.0

Abby

167

Developer Tools · Product Management

Statically typed feature flags, remote config, and A/B testing with framework-native SDKs for TypeScript teams.

App
Built with
  • TypeScript 76%
  • MDX 18%
Updated 1 years agoView details
TypeScript 100%Other

Activepieces

25,653

AI Assistants · Automation · Mcp

Open-source AI automation platform that converts 280+ workflow integrations into MCP servers for LLMs, with no-code builders and TypeScript extensibility.

App
Built with
  • TypeScript 100%
Updated yesterdayView details
TypeScript 81%Other

AFFiNE

75,903

Collaboration · Note Taking · Productivity

Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.

App
Built with
  • TypeScript 81%
  • Rust 11%
Updated yesterdayView details
Python 99%MIT

Agent Lightning

18,988

AI Development

A Microsoft-built training framework that optimizes AI agents with reinforcement learning, automatic prompt optimization, or supervised fine-tuning — with near-zero code changes to your existing agent, in any framework.

App
Built with
  • Python 99%
Updated 1 weeks agoView details
TypeScript 50%Apache 2.0

agent-orchestrator

14,975

AI Agents · AI Code Assistants · Developer Tools

A local desktop workspace that gives every coding task its own agent, Git branch, and worktree, then tracks tasks, pull requests, CI, and reviews for 27 coding agents on one live Kanban board.

App
Built with
  • TypeScript 50%
  • Go 48%
Updated todayView details
TypeScript 57%Other

agenta

4,924

AI Development · Developer Tools · Devops

The open-source LLMOps platform unifying prompt engineering, evaluation, and observability for teams building reliable LLM applications.

App
Built with
  • TypeScript 57%
  • Python 39%
Updated todayView details
TypeScript 86%MIT

Agents Observe

738

Developer Tools

A real-time, fully local observability dashboard for Claude Code and Codex agent sessions — filtering, search, session replay, and token/cost breakdowns via an auto-starting MCP server.

App
Built with
  • TypeScript 86%
  • JavaScript 10%
Updated 2 months agoView details
Python 51%Other

Airbyte

22,424

Data Engineering · Developer Tools

Open-source ELT platform with 600+ connectors for moving data from any source to warehouses, lakes, and AI agents.

App
Built with
  • Python 51%
  • Kotlin 43%
Updated todayView details
TypeScript 89%MIT

Amical

1,647

AI Assistants · Note Taking · Voice AI

Local-first AI dictation that understands your active app — private, offline, and built for speed.

App
Built with
  • TypeScript 89%
Updated 3 days agoView details

Join founders building with open source

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

Subscribe on SubstackJoin 750+ subscribers