---
title: "Introduction"
description: "First-class variants, slots, and compound styles for UnoCSS — a port of Tailwind Variants that leaves conflict resolution to the CSS cascade."
canonical_url: "https://vinicunca.dev/unocss-variants/getting-started"
---
# Introduction

> First-class variants, slots, and compound styles for UnoCSS — a port of Tailwind Variants that leaves conflict resolution to the CSS cascade.

**UnoCSS Variants** (`unocss-variants`) is a first-class variant API for [UnoCSS](https://unocss.dev/). You define a component recipe once — base styles, variants, defaults, slots, and compound rules — and call it anywhere with typed props.

It is a port of [Tailwind Variants](https://www.tailwind-variants.org/). The important difference: **classes are never merged**. Conflicting utilities stay in the class string; you resolve them with UnoCSS [layers](https://vinicunca.dev/unocss-variants/concepts/layers) and the CSS cascade.

> [!NOTE]
> 
> `uv(options)` takes **one** argument. There is no config object, no `twMerge`, no `/lite` build, and no responsive-variant map. Put breakpoint prefixes such as `md:` in the class strings yourself.

## Why UnoCSS Variants

**One recipe, many call sites**

Change `color` or `size` at the call site instead of editing long class strings.

**Slots for multi-part UI**

Cards, alerts, and pagination get named parts, each with its own classes and variants.

**Compound rules**

Apply extra classes when several variant keys match, or to several slots at once.

**TypeScript-first**

Infer call-site props with `VariantProps`. Slotted recipes return typed slot functions.

## Key features

### Variants

Define axes like `color`, `size`, or boolean flags such as `disabled`. Combine them independently.

```vue
<template>
  <uv-button :uv="{
    base: 'font-medium bg-blue-500 color-white rounded-full active:opacity-80',
    variants: {
      color: {
        primary: 'bg-blue-500 color-white',
        secondary: 'bg-purple-500 color-white'
      },
      size: {
        sm: 'text-sm',
        md: 'text-base',
        lg: 'px-4 py-3 text-lg'
      }
    },
    defaultVariants: {
      size: 'md',
      color: 'primary'
    },
    compoundVariants: [
      {
        size: [
          'sm',
          'md'
        ],
        class: 'px-3 py-1'
      }
    ]
  }" as="button" color="secondary" size="sm">
    <p>
      Click me
    </p>
  </uv-button>
</template>
```

```vue
<script setup>
import { uv } from 'unocss-variants';

const button = uv({
  base: 'font-medium bg-blue-500 color-white rounded-full active:opacity-80',
  variants: {
    color: {
      primary: 'bg-blue-500 color-white',
      secondary: 'bg-purple-500 color-white'
    },
    size: {
      sm: 'text-sm',
      md: 'text-base',
      lg: 'px-4 py-3 text-lg'
    }
  },
  compoundVariants: [
    {
      size: ['sm', 'md'],
      class: 'px-3 py-1'
    }
  ],
  defaultVariants: {
    size: 'md',
    color: 'primary'
  }
});
</script>

<template>
  <button :class="button({ size: 'sm', color: 'secondary' })">
    Click me
  </button>
</template>
```

```ts
button({ size: 'sm', color: 'secondary' });
// font-medium bg-blue-500 color-white rounded-full active:opacity-80 bg-purple-500 color-white text-sm px-3 py-1
```

Every class is kept, including both `bg-blue-500` from `base` and `bg-purple-500` from the variant. See [Layers](https://vinicunca.dev/unocss-variants/concepts/layers) for how to make the variant win.

See [Variants](https://vinicunca.dev/unocss-variants/concepts/variants) for boolean variants, compound variants, and defaults.

### Slots

Split a component into named parts and style each one.

```vue
<template>
  <uv-slot-card />
</template>
```

See [Slots](https://vinicunca.dev/unocss-variants/concepts/slots).

### Overrides

Pass `class` or `className` when you call the recipe. The extra classes are **appended** — they do not replace conflicting utilities.

```ts
button({
  color: 'secondary',
  class: 'bg-pink-500 hover:bg-pink-500'
});
// font-semibold color-white py-1 px-3 rounded-full active:opacity-80 bg-purple-500 hover:bg-purple-700 bg-pink-500 hover:bg-pink-500
```

See [Overriding styles](https://vinicunca.dev/unocss-variants/concepts/overriding-styles).

### Composition

`extend` merges another recipe's `base`, `slots`, `variants`, `defaultVariants`, `compoundVariants`, and `compoundSlots`.

```vue
<template>
  <uv-compose-buttons />
</template>
```

Child classes that must win over the parent should use the `uno-layer-uv:` prefix. See [Composing components](https://vinicunca.dev/unocss-variants/concepts/composing-components) and [Layers](https://vinicunca.dev/unocss-variants/concepts/layers).

## What is not included

- **No class merging** — unlike default Tailwind Variants, `uv` never drops conflicting utilities.
- **No second config argument** — and no `createTV` / `twMerge` / `cnMerge`.
- **No /lite entry** — there is a single build.
- **No responsiveVariants map** — write `sm:` / `md:` in the class strings.
- **No breakpoint autocompletion** — TypeScript completes variant keys and slot names, not media queries.

Coming from Tailwind Variants? Read the [migration guide](https://vinicunca.dev/unocss-variants/guides/migration).

## Credits

UnoCSS Variants is a fork of [Tailwind Variants](https://www.tailwind-variants.org/). Credit to the original authors, and to [Stitches](https://stitches.dev/) and [CVA](https://cva.style/) for the variant model.

---

- [Source](https://github.com/praburangki/unocss-variants)
- [npm](https://www.npmjs.com/package/unocss-variants)


## Sitemap

See the full [sitemap](https://vinicunca.dev/sitemap.md) for all pages.
