Add Tailwind CSS
Components are styled using Tailwind CSS. You need to install Tailwind CSS in your project.
Follow the Tailwind CSS installation instructions to get started.
Add Dependencies
Add the following dependencies to your project:
npx add class-variance-authority clsx tailwind-merge @heroicons/react @headlessui/react
Configure Path Aliases
Configure the path aliases in your tsconfig.json
file.
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
}
}
}
The @
alias is a preference. You can use other aliases if you want.
Configure Styles
Add the following to your styles/globals.css
file.
@import "tailwindcss";
@custom-variant dark (&:is(.dark *));
@custom-variant fixed (&:is(.layout-fixed *));
:root {
--radius: 0.65rem;
--background: oklch(1 0 0);
--foreground: oklch(0.141 0.005 285.823);
--primary: oklch(0.606 0.25 292.717);
--primary-foreground: oklch(0.969 0.016 293.756);
--secondary: oklch(0.967 0.001 286.375);
--secondary-foreground: oklch(0.21 0.006 285.885);
--muted: oklch(0.967 0.001 286.375);
--muted-foreground: oklch(0.552 0.016 285.938);
--accent: oklch(0.967 0.001 286.375);
--accent-foreground: oklch(0.21 0.006 285.885);
--destructive: oklch(0.577 0.245 27.325);
--border: oklch(0.92 0.004 286.32);
}
.dark {
--background: oklch(0.141 0.005 285.823);
--foreground: oklch(0.985 0 0);
--primary: oklch(0.541 0.281 293.009);
--primary-foreground: oklch(0.969 0.016 293.756);
--secondary: oklch(0.274 0.006 286.033);
--secondary-foreground: oklch(0.985 0 0);
--muted: oklch(0.274 0.006 286.033);
--muted-foreground: oklch(0.705 0.015 286.067);
--accent: oklch(0.274 0.006 286.033);
--accent-foreground: oklch(0.985 0 0);
--destructive: oklch(0.704 0.191 22.216);
--border: oklch(1 0 0 / 7.5%);
}
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-primary: var(--primary);
--color-primary-foreground: var(--primary-foreground);
--color-secondary: var(--secondary);
--color-secondary-foreground: var(--secondary-foreground);
--color-muted: var(--muted);
--color-muted-foreground: var(--muted-foreground);
--color-accent: var(--accent);
--color-accent-foreground: var(--accent-foreground);
--color-destructive: var(--destructive);
--color-border: var(--border);
--radius-sm: calc(var(--radius) - 4px);
--radius-md: calc(var(--radius) - 2px);
--radius-lg: var(--radius);
--radius-xl: calc(var(--radius) + 4px);
}
@layer base {
*:focus-visible {
@apply outline-primary outline-2 outline-offset-2;
}
*:focus:not(:focus-visible) {
@apply outline-none;
}
body {
font-synthesis-weight: none;
text-rendering: optimizeLegibility;
@apply bg-background text-foreground;
}
}
Add a cn Helper
// lib/utils.ts
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
Create a components.json
file
Create a components.json
file in the root of your project.
{
"$schema": "https://ui.headcn.site/schema.json",
"style": "default",
"rsc": true,
"tsx": true,
"tailwind": {
"css": "styles/globals.css",
"prefix": ""
},
"iconLibrary": "@heroicons/react",
"aliases": {
"components": "@/components",
"ui": "@/components/ui",
"lib": "@/lib"
}
}
That's it
You can now start adding components to your project.