GitHub
2.64k
Created 2 years ago, last commit 4 days ago
23 contributors
165 commits
Stars added on GitHub, month by month
3
4
5
6
7
8
9
10
11
12
1
2
2024
2025
Stars added on GitHub, per day, on average
Yesterday
+5
Last week
+3.3
/day
Last month
+1.8
/day
Last 12 months
+2.3
/day
npmPackage on NPM
Monthly downloads on NPM
3
4
5
6
7
8
9
10
11
12
1
2
2024
2025
README

tailwind-variants

tailwind-variants

The power of Tailwind combined with a first-class variant API.

npm downloads NPM Version License

Features

  • First-class variant API
  • Slots support
  • Composition support
  • Fully typed
  • Framework agnostic
  • Automatic conflict resolution
  • Tailwindcss V4 support

Documentation

For full documentation, visit tailwind-variants.org

ā• Note: Tailwindcss V4 no longer supports the config.content.transform so we remove the responsive variants feature

If you want to use responsive variants, you need to add it manually to your classname.

Quick Start

  1. Installation: To use Tailwind Variants in your project, you can install it as a dependency:
yarn add tailwind-variants
# or
npm i tailwind-variants
  1. Usage:
import {tv} from "tailwind-variants";

const button = tv({
  base: "font-medium bg-blue-500 text-white rounded-full active:opacity-80",
  variants: {
    color: {
      primary: "bg-blue-500 text-white",
      secondary: "bg-purple-500 text-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",
  },
});

return <button className={button({size: "sm", color: "secondary"})}>Click me</button>;

Acknowledgements

  • cva (Joe Bell) This project as started as an extension of Joe's work on cva ā€“ a great tool for generating variants for a single element with Tailwind CSS. Big shoutout to Joe Bell and contributors you guys rock! šŸ¤˜ - we recommend to use cva if don't need any of the Tailwind Variants features listed here.

  • Stitches (Modulz)
    The pioneers of the variants API movement. Inmense thanks to Modulz for their work on Stitches and the community around it. šŸ™

Community

We're excited to see the community adopt HeroUI, raise issues, and provide feedback. Whether it's a feature request, bug report, or a project to showcase, please get involved!

Contributing

Contributions are always welcome!

Please follow our contributing guidelines.

Please adhere to this project's CODE_OF_CONDUCT.

Authors

License

Licensed under the MIT License.

See LICENSE for more information.