# Utils

> Class name merging helper combining clsx and tailwind-merge.

Canonical URL: https://taut-ui.com/docs/lib/utils

A small helper that joins conditional class names with `clsx` and resolves conflicting Tailwind CSS utility classes with `tailwind-merge`. Every component in **taut ui** imports `cn` from `@/lib/utils`.

## Installation [#installation]

**CLI**

```bash
npx shadcn@latest add https://taut-ui.com/r/utils.json
```

**Manual**

- Install the following dependencies:

```bash
npm install clsx tailwind-merge
```

- Copy and paste the following code into your project.

```tsx title="lib/utils.ts"
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]): string {
  return twMerge(clsx(inputs));
}
```

## Usage [#usage]

### Conditional Classes & Overrides [#conditional-classes--overrides]

Pass strings, objects, arrays, or `undefined` values—later Tailwind utilities override earlier conflicting ones cleanly:

```tsx
import { cn } from "@/lib/utils";

export function Surface({
  active,
  className,
}: {
  active?: boolean;
  className?: string;
}) {
  return (
    <div
      className={cn(
        "rounded-2xl bg-card px-4 py-2 text-card-foreground",
        active && "bg-primary text-primary-foreground",
        className,
      )}
    />
  );
}
```

## API [#api]

```ts
function cn(...inputs: ClassValue[]): string
```

| Parameter | Type | Description |
|-----------|------|-------------|
| `...inputs` | `ClassValue[]` | Class strings, objects, arrays, or falsy values accepted by `clsx`. |
