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:
npm install @base-ui-components/react class-variance-authority clsx tailwind-merge lucide-react
Copy Configure the path aliases in your tsconfig.json
file.
tsconfig.json {
"compilerOptions" : {
"baseUrl" : "." ,
"paths" : {
"@/*" : [ "./*" ]
}
}
}
Copy The @
alias is a preference. You can use other aliases if you want.
Here's what my tailwind.config.js
file looks like:
tailwind.config.js /** @type {import('tailwindcss').Config} */
module . exports = {
darkMode: [ "class" ],
content: [ "app/**/*.{ts,tsx}" , "components/**/*.{ts,tsx}" ],
theme: {
extend: {
colors: {
border: "hsl(var(--border))" ,
input: "hsl(var(--input))" ,
ring: "hsl(var(--ring))" ,
background: "hsl(var(--background))" ,
foreground: "hsl(var(--foreground))" ,
primary: {
DEFAULT: "hsl(var(--primary))" ,
foreground: "hsl(var(--primary-foreground))" ,
},
secondary: {
DEFAULT: "hsl(var(--secondary))" ,
foreground: "hsl(var(--secondary-foreground))" ,
},
destructive: {
DEFAULT: "hsl(var(--destructive))" ,
foreground: "hsl(var(--destructive-foreground))" ,
},
muted: {
DEFAULT: "hsl(var(--muted))" ,
foreground: "hsl(var(--muted-foreground))" ,
},
accent: {
DEFAULT: "hsl(var(--accent))" ,
foreground: "hsl(var(--accent-foreground))" ,
},
popover: {
DEFAULT: "hsl(var(--popover))" ,
foreground: "hsl(var(--popover-foreground))" ,
},
card: {
DEFAULT: "hsl(var(--card))" ,
foreground: "hsl(var(--card-foreground))" ,
},
},
borderRadius: {
lg: `var(--radius)` ,
md: `calc(var(--radius) - 2px)` ,
sm: "calc(var(--radius) - 4px)" ,
},
},
},
}
Copy Add the following to your globals.css file.
globals.css @tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
:root {
--background : 0 0 % 100 % ;
--foreground : 0 0 % 3.9 % ;
--muted : 0 0 % 96.1 % ;
--muted-foreground : 0 0 % 45.1 % ;
--popover : 0 0 % 100 % ;
--popover-foreground : 0 0 % 3.9 % ;
--border : 0 0 % 89.8 % ;
--input : 0 0 % 89.8 % ;
--card : 0 0 % 100 % ;
--card-foreground : 0 0 % 3.9 % ;
--primary : 0 0 % 9 % ;
--primary-foreground : 0 0 % 98 % ;
--secondary : 0 0 % 96.1 % ;
--secondary-foreground : 0 0 % 9 % ;
--accent : 0 0 % 96.1 % ;
--accent-foreground : 0 0 % 9 % ;
--destructive : 0 84.2 % 60.2 % ;
--destructive-foreground : 0 0 % 98 % ;
--ring : 0 0 % 3.9 % ;
--radius : 10 px ;
}
.dark {
--background : 0 0 % 3.9 % ;
--foreground : 0 0 % 98 % ;
--muted : 0 0 % 14.9 % ;
--muted-foreground : 0 0 % 63.9 % ;
--accent : 0 0 % 14.9 % ;
--accent-foreground : 0 0 % 98 % ;
--popover : 0 0 % 3.9 % ;
--popover-foreground : 0 0 % 98 % ;
--border : 0 0 % 14.9 % ;
--input : 0 0 % 14.9 % ;
--card : 0 0 % 3.9 % ;
--card-foreground : 0 0 % 98 % ;
--primary : 0 0 % 98 % ;
--primary-foreground : 0 0 % 9 % ;
--secondary : 0 0 % 14.9 % ;
--secondary-foreground : 0 0 % 98 % ;
--destructive : 0 62.8 % 30.6 % ;
--destructive-foreground : 0 0 % 98 % ;
--ring : 0 0 % 83.1 % ;
}
}
@layer base {
* {
@ apply border-border ;
}
body {
@ apply bg-background font-sans text-foreground antialiased ;
}
}
Copy 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))
}
Copy Set up portals Base UI uses portals for components that render popups, such as Dialog and Popover. To make portalled components always appear on top of the entire page, add the following style to your application layout root:
< body >
< div className = "isolate" >{children}</ div >
</ body >
Copy This style creates a separate stacking context for your applicationβs root element. This way, popups will always appear above the page contents, and any z-index property in your styles wonβt interfere with them.
That's it You can now start adding components to your project.