{
 "kind": "tool",
 "slug": "clsx",
 "path": "tools/clsx/",
 "name": "clsx",
 "maker": null,
 "density": "full",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Utilities",
   "tools/utilities/"
  ]
 ],
 "lead": "Build class names from conditions.",
 "chips": [
  {
   "label": "Utilities",
   "path": "tools/utilities/"
  },
  {
   "label": "NPM"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "npm install clsx"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/lukeed/clsx"
  },
  {
   "label": "Website",
   "href": "https://github.com/lukeed/clsx#readme"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "MIT",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": "to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software",
   "note": "MIT allows use in paid and closed-source products.",
   "src": "https://github.com/lukeed/clsx/blob/master/license"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Quiet for a year",
   "status": "cond",
   "sub": "Last change Jun 10, 2024",
   "note": "Latest GitHub release Apr 23, 2024. ",
   "src": "https://github.com/lukeed/clsx"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "1,212 projects",
   "status": "info",
   "sub": "#1 of 408 in its category",
   "note": "Dependency in 1,212 public GitHub projects set up for AI coding agents that we scanned (19.4%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Docs for agents",
   "status": "yes",
   "sub": "llms.txt",
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": "https://code.visualstudio.com/llms.txt"
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily; card checked Nov 10, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What clsx does",
   "parts": [
    {
     "t": "prose",
     "text": "clsx is a tiny free JavaScript helper that writes the class names of a button, link or card from its state. Your app says \"add the active style only when this tab is open\", and clsx returns the right text, such as \"tab tab-active\". It does not style anything itself; your CSS or Tailwind CSS does that."
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "Buttons that change with state",
       "text": "A Save button looks different when it is the main action, pressed or turned off; your code passes the state and gets the matching class names back.",
       "idea": false
      },
      {
       "title": "Tailwind CSS classes by condition",
       "text": "In a Tailwind CSS project, a link gets a highlight color only when it is the current page, and the editor can still suggest class names inside clsx.",
       "idea": false
      },
      {
       "title": "Swap out the classnames package",
       "text": "An older project that uses the classnames package can switch to clsx without rewriting the calls, and the app gets a bit smaller.",
       "idea": false
      },
      {
       "title": "Let a parent add its own classes",
       "text": "A reusable card or button keeps its own look and still accepts extra class names from the screen that uses it.",
       "idea": false
      },
      {
       "title": "Red border on a form field with an error",
       "text": "A sign-up form marks the email field in red only after the check fails, and clears it when the person fixes the address.",
       "idea": true
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "clsx popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "82",
       "of": "/ 100",
       "l": "Gid Score, #62 overall"
      },
      {
       "n": "179M",
       "l": "downloads a week, npm"
      },
      {
       "n": "9,848",
       "l": "GitHub stars"
      },
      {
       "n": "1,212",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How clsx is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "clsx is a dependency in 1,212 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (24.9% of the 4,867 JavaScript/TypeScript ones), #1 of 408 in utilities.",
      "Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 4,538; those are left out of every share on this page.",
      "The most used alternative in our scan is Lodash (111 projects).",
      "Projects that use it most often also use Tailwind Merge (94.9%), Lucide React (85.1%), Class Variance Authority (82.4%).",
      "It is more common in projects set up for Roo Code (29.7%) than for OpenAI Codex (15.8%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "625 projects, 19.1%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "602 projects, 24.7%",
       "v": "Cursor",
       "path": "agents/cursor/"
      },
      {
       "l": "559 projects, 18.4%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      },
      {
       "l": "100 projects, 21.1%",
       "v": "Gemini CLI",
       "path": "agents/gemini-cli/"
      },
      {
       "l": "74 projects, 15.8%",
       "v": "OpenAI Codex",
       "path": "agents/openai-codex/"
      },
      {
       "l": "74 projects, 26.5%",
       "v": "Devin Desktop",
       "path": "agents/devin-desktop/"
      },
      {
       "l": "66 projects, 19.2%",
       "v": "OpenCode",
       "path": "agents/opencode/"
      },
      {
       "l": "33 projects, 29.7%",
       "v": "Roo Code",
       "path": "agents/roo-code/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 94.9% of its projects",
       "v": "Tailwind Merge",
       "path": "tools/tailwind-merge/"
      },
      {
       "l": "In 85.1% of its projects",
       "v": "Lucide React",
       "path": "tools/lucide-react/"
      },
      {
       "l": "In 82.4% of its projects",
       "v": "Class Variance Authority",
       "path": "tools/class-variance-authority/"
      },
      {
       "l": "In 97.9% of its projects",
       "v": "Tailwind CSS",
       "path": "tools/tailwindcss/"
      },
      {
       "l": "In 93.7% of its projects",
       "v": "React",
       "path": "tools/react/"
      },
      {
       "l": "In 64.0% of its projects",
       "v": "Radix UI",
       "path": "tools/radix-ui/"
      },
      {
       "l": "In 63.0% of its projects",
       "v": "Next.js",
       "path": "tools/next/"
      },
      {
       "l": "In 46.1% of its projects",
       "v": "Sonner",
       "path": "tools/sonner/"
      }
     ]
    }
   ]
  },
  {
   "id": "profile",
   "nav": "Profile",
   "h2": "clsx in practice",
   "parts": [
    {
     "t": "h3",
     "text": "Strengths"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "Strings, objects and nested arrays in one call",
       "v": "One function takes any number of mixed arguments and flattens nested arrays. The README example <code>clsx('foo', [1 &amp;amp;&amp;amp; 'bar', { baz:false, bat:null }, ['hello', ['world']]], 'cya')</code> returns <code>'foo bar hello world cya'</code>."
      },
      {
       "l": "A smaller build when you only pass strings",
       "v": "The default module is 239 bytes gzipped. <code>clsx/lite</code> is 140 bytes and handles only string arguments. You import whichever build matches how you compose classes."
      },
      {
       "l": "Pitched as a swap-in for classnames",
       "v": "The maintainer describes clsx as a faster and smaller drop-in replacement for <code>classnames</code>. Cross-browser benchmark snapshots are kept in the repo's <code>bench</code> directory."
      },
      {
       "l": "Three module formats",
       "v": "The package ships ESM (<code>dist/clsx.mjs</code>), CommonJS (<code>dist/clsx.js</code>) and a minified UMD file. You can use either a default or a named import."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Watch out for"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "0, NaN and bare booleans are dropped",
       "v": "Every falsey value is discarded, including <code>0</code> and <code>NaN</code>. Standalone <code>true</code> is discarded too. <code>clsx(true, false, '', null, undefined, 0, NaN)</code> returns an empty string."
      },
      {
       "l": "clsx/lite silently ignores objects",
       "v": "If you pass an object or array to the lite build, nothing is added and no error is raised. <code>clsx({ foo: true })</code> from <code>clsx/lite</code> returns <code>\"\"</code>."
      },
      {
       "l": "Tailwind autocompletion needs manual setup",
       "v": "Class autocompletion inside <code>clsx()</code> calls does not work by default. In VS Code, the README says to install the Tailwind CSS IntelliSense extension and add a <code>tailwindCSS.experimental.classRegex</code> entry to <code>settings.json</code>."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Every input shape clsx accepts"
    },
    {
     "t": "tabs",
     "label": "Example",
     "items": [
      {
       "tab": "Js",
       "code": "import clsx from 'clsx';\n// or\nimport { clsx } from 'clsx';\n\n// Strings (variadic)\nclsx('foo', true && 'bar', 'baz');\n//=> 'foo bar baz'\n\n// Objects\nclsx({ foo:true, bar:false, baz:isTrue() });\n//=> 'foo baz'\n\n// Objects (variadic)\nclsx({ foo:true }, { bar:false }, null, { '--foobar':'hello' });\n//=> 'foo --foobar'\n\n// Arrays\nclsx(['foo', 0, false, 'bar']);\n//=> 'foo bar'\n\n// Arrays (variadic)\nclsx(['foo'], ['', 0, false, 'bar'], [['baz', [['hello'], 'there']]]);\n//=> 'foo bar baz hello there'\n\n// Kitchen sink (with nesting)\nclsx('foo', [1 && 'bar', { baz:false, bat:null }, ['hello', ['world']]], 'cya');\n//=> 'foo bar hello world cya'"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "profile",
   "h2": "More about clsx",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "Funding",
       "path": "tools/funding/",
       "items": [
        "GitHub Sponsors: https://github.com/lukeed",
        "8 GitHub sponsors"
       ]
      },
      {
       "title": "Packages around it",
       "items": [
        "tailwind-merge: Tailwind class merging",
        "lucide-react: Icon components",
        "class-variance-authority: Component variants",
        "tailwindcss: Utility-first CSS",
        "@radix-ui: UI primitives",
        "react: UI library"
       ]
      },
      {
       "title": "More in Utilities",
       "path": "tools/utilities/",
       "items": [
        {
         "text": "date-fns",
         "path": "tools/date-fns/"
        },
        {
         "text": "PyYAML",
         "path": "tools/pyyaml/"
        },
        {
         "text": "uuid",
         "path": "tools/uuid/"
        },
        {
         "text": "yaml",
         "path": "tools/yaml/"
        },
        {
         "text": "js-yaml",
         "path": "tools/js-yaml/"
        },
        {
         "text": "glob",
         "path": "tools/glob/"
        },
        {
         "text": "tqdm",
         "path": "tools/tqdm/"
        },
        {
         "text": "Nanoid (JavaScript)",
         "path": "tools/nanoid-npm/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "clsx",
       "me": true,
       "facts": [
        "MIT",
        "Gid 82",
        "179M/wk"
       ]
      },
      {
       "name": "classnames",
       "why": "Pick classnames if your project already uses it everywhere; clsx is a drop-in replacement, so there is no need to switch in a hurry.",
       "path": "tools/classnames/",
       "facts": []
      },
      {
       "name": "Tailwind Merge",
       "why": "Pick tailwind-merge when Tailwind CSS classes can clash (two paddings, two colors) and the later one must win.",
       "path": "tools/tailwind-merge/",
       "facts": []
      },
      {
       "name": "Class Variance Authority",
       "why": "Pick class-variance-authority when a component has named variants such as size and intent that you want to define in one typed place.",
       "path": "tools/class-variance-authority/",
       "facts": []
      },
      {
       "name": "Lodash",
       "why": "Modular utility library with methods for common programming tasks and data manipulation.",
       "path": "tools/lodash/",
       "facts": [
        "MIT",
        "Gid 84",
        "212M/wk"
       ]
      }
     ],
     "more": "Compare clsx with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "Use the npm package clsx (pin clsx@2.1.1) to build each component's className from its state, for example clsx('btn', { 'btn-primary': primary, 'btn-disabled': disabled }), instead of joining strings by hand."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Add clsx to your project.",
       "code": "$ npm install --save clsx",
       "src": "https://github.com/lukeed/clsx/blob/master/readme.md"
      },
      {
       "text": "Import it and pass strings, objects or lists; false, empty and missing values are dropped.",
       "code": "import clsx from 'clsx';\n// or\nimport { clsx } from 'clsx';\n\n// Strings (variadic)\nclsx('foo', true && 'bar', 'baz');\n//=> 'foo bar baz'\n\n// Objects\nclsx({ foo:true, bar:false, baz:isTrue() });\n//=> 'foo baz'\n",
       "src": "https://github.com/lukeed/clsx/blob/master/readme.md"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Rules for your agent"
    },
    {
     "t": "rules",
     "label": "Paste into AGENTS.md or CLAUDE.md",
     "text": "## clsx\n- Import with either `import clsx from 'clsx'` or `import { clsx } from 'clsx'`. Both forms work.\n- Never rely on `0`, `NaN` or a bare `true` to produce a class. All falsey values and standalone booleans are discarded.\n- Use the object form `{ name: condition }` or the `cond &amp;&amp; 'name'` string form for conditional classes. Arrays may be nested to any depth.\n- Import from `clsx/lite` only when every call passes strings. Lite silently ignores objects and arrays, so `clsx({ foo: true })` returns `\"\"`.\n- For Tailwind autocompletion in VS Code, add the README's `tailwindCSS.experimental.classRegex` entry for `clsx\\(([^)]*)\\)` to `settings.json`.\n- If IE8 support is required, pin `clsx@1.0.x`. Current versions need `Array.isArray` (IE9+).\n"
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "import { clsx } from 'clsx/lite' and pass objects like { 'btn-lg': isLarge }",
       "fix": "Use the full import from 'clsx' whenever any argument is an object or a list",
       "why": "clsx/lite accepts only strings; in our run lite('btn', { 'btn-lg': true }) returned 'btn'."
      },
      {
       "dont": "clsx('p-2', isLarge && 'p-4') expecting p-4 to replace p-2 in Tailwind CSS",
       "fix": "Wrap it with tailwind-merge, twMerge(clsx(...)), when classes can clash",
       "why": "clsx keeps both names, and which one wins then depends on the CSS order, not on the call."
      },
      {
       "dont": "Deep imports of build files from version 1, such as 'clsx/dist/clsx.m.js'",
       "fix": "import clsx from 'clsx' (or 'clsx/lite'); version 2 only exposes these two entry points",
       "why": "Version 2.0.0 added an exports map; the 2.1.1 package we unpacked has dist/clsx.mjs, clsx.js, clsx.min.js and lite files, no clsx.m.js."
      },
      {
       "dont": "clsx('badge', count) to show a class only when there is a count",
       "fix": "clsx('badge', count > 0 && 'badge-has-items')",
       "why": "A number is added as text (here the count itself), and 0 is dropped as falsey, so the class you meant never appears."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "Can I use it in a paid, closed-source app?",
       "a": "Yes. It is MIT licensed; keep the copyright and license notice with the package.",
       "evidence": {
        "url": "https://github.com/lukeed/clsx/blob/master/license",
        "quote": "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software."
       }
      },
      {
       "q": "Is it the same as the classnames package?",
       "a": "It does the same job and the README calls it a faster and smaller drop-in replacement for classnames.",
       "evidence": {
        "url": "https://github.com/lukeed/clsx/blob/master/readme.md",
        "quote": "Also serves as a faster & smaller drop-in replacement for the classnames module."
       }
      },
      {
       "q": "Why did my class with the value 0 disappear?",
       "a": "clsx drops every falsey value, and 0 is one of them; pass a string or a real true/false condition instead.",
       "evidence": {
        "url": "https://github.com/lukeed/clsx/blob/master/readme.md",
        "quote": "Any falsey values are discarded!"
       }
      },
      {
       "q": "Is it still maintained?",
       "a": "The latest release is 2.1.1, published on 23 April 2024; the package is small and stable, and the README names no successor.",
       "evidence": {
        "url": "https://registry.npmjs.org/clsx",
        "quote": "\"2.1.1\":\"2024-04-23T05:26:04.645Z\""
       }
      },
      {
       "q": "Does it fix clashing Tailwind CSS classes?",
       "a": "No. clsx only joins names; tailwind-merge is the separate helper that removes clashing Tailwind CSS classes.",
       "evidence": {
        "url": "https://github.com/dcastil/tailwind-merge/blob/main/README.md",
        "quote": "Utility function to efficiently merge Tailwind CSS classes in JS without style conflicts."
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "npm clsx"
  ],
  [
   "Category",
   "Utilities"
  ],
  [
   "License",
   "MIT"
  ],
  [
   "Latest version",
   "v2.1.1, April 23, 2024"
  ],
  [
   "On GitHub since",
   "December 2018"
  ],
  [
   "Gid Score",
   "82.5"
  ],
  [
   "Rank in category",
   "#1 of 408"
  ],
  [
   "GitHub",
   "lukeed/clsx"
  ],
  [
   "Last change",
   "Jun 10, 2024"
  ]
 ],
 "good": [
  "Any value that counts as empty or false, including the number 0, is dropped from the result.",
  "The smaller clsx/lite version accepts only plain text pieces; conditions written as objects are silently ignored.",
  "It works in every Node.js version and in browsers back to Internet Explorer 9."
 ],
 "checked_line": "Read by AgentGid from 6 official pages, card checked Nov 10, 2026; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/lukeed.png"
}