classix

The tiniest and fastest utility for conditionally joining classNames using plain string expressions.

Library
npm
v2.2.18
216stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
60/100Good
Development Activity60
Maintenance68
Community36
Maturity56
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture78
Code Quality84
Innovation76
Learning Curve55

classix is a minimal utility for conditionally joining CSS class names into a single string. It exposes a single cx function that concatenates any number of string expressions, skipping falsy values, which makes it a natural fit for conditional styling in React and Tailwind projects.

Unlike clsx or classnames, classix deliberately accepts only string expressions — no objects or arrays of conditions. This constraint yields a simpler, consistent API, a smaller bundle footprint, and faster runtime performance, while conditions are expressed naturally with && and ternary operators.

What You Get

  • A single cx function (default and named export) that joins className strings
  • Automatic removal of falsy values so condition && 'class' just works
  • Full TypeScript types for a typed, autocomplete-friendly API
  • A very small bundle size and best-in-class runtime performance
  • Zero dependencies and ESM/CJS compatibility

Common Use Cases

  • Conditionally composing Tailwind utility classes in React components
  • Toggling classes based on props or state with ternaries and &&
  • Replacing clsx/classnames where only string conditions are needed to shrink bundle size
  • Building className strings in any JSX framework or plain JavaScript

Under The Hood

Architecture - The entire library is a single tiny function that iterates its arguments, keeps the truthy string values, and joins them with a space. There is no object/array parsing branch, which is precisely why it is smaller and faster than clsx-style utilities. Tech Stack - Written in TypeScript and published as both ESM and CJS with type declarations; zero runtime dependencies. Tooling includes benchmark and size-comparison scripts and Codecov-tracked coverage. Code Quality - Despite its size, the repo maintains full test coverage, benchmarks against competitors, and typed exports — a well-cared-for micro-library. API Design - The API is intentionally minimal: import cx, pass string expressions, get a string. Conditions read naturally (isActive && 'active', big ? 'p-4' : 'p-2'), so there is essentially nothing to learn for anyone familiar with className joining.

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

Search