Remix
A comprehensive guide on installing and configuring shadcn/ui components specifically for Remix projects.
Note: The following guide is for Tailwind v4. If you are using Tailwind
v3, use shadcn@2.3.0.
Note: This guide is for Remix. For React Router, see the React Router guide.
Step 1: Initialize Your Remix Project
Begin the installation process by creating a new Remix project using the create-remix command-line tool:
npx create-remix@latest my-appStep 2: Execute the shadcn/ui Initialization Command
Run the shadcn/ui initialization command in your terminal to configure your project for using shadcn/ui components:
npx shadcn@latest initStep 3: Configure the components.json File
You will be guided through a series of questions to configure the components.json file. This file is essential for customizing the behavior and location of shadcn/ui components within your project. Respond to the prompts as follows:
Which style would you like to use? › New York
Which color would you like to use as base color? › Zinc
Do you want to use CSS variables for colors? › no / yesStep 4: Understanding the Recommended App Structure
Note: This app structure is only a suggestion. You can place the files wherever you want.
UI Components: It is recommended to place the shadcn/ui components within the
app/components/uifolder for clear separation.Your Components: Your own custom React components can reside in the
app/componentsfolder.Utility Functions: The
app/libfolder is a suitable location for all utility functions, including thecnhelper function typically defined in autils.tsfile.Global Styles: The main
app/tailwind.cssfile should contain your project's global CSS styles.
Step 5: Install and Configure Tailwind CSS
npm install -D tailwindcss@latest autoprefixer@latestNext, create a postcss.config.js file at the root of your project with the following configuration:
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};Finally, update your remix.config.js file to enable Tailwind CSS and PostCSS processing:
/** @type {import('@remix-run/dev').AppConfig} */
export default {
...
tailwind: true,
postcss: true,
...
};Step 6: Include tailwind.css in Your Application
In your application's root file, typically app/root.tsx, import the tailwind.css file to ensure your styles are included in the build:
export const links: LinksFunction = () => [
{ rel: "stylesheet", href: styles },
...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
]Step 7: Begin Adding Components
You have now successfully completed the initial setup. Your Remix project is configured, and you can begin adding individual shadcn/ui components using the npx shadcn@latest add command.
npx shadcn@latest add buttonExecuting the command shown above will add the Button component files to your project structure. You can then import and use the component in your Remix files as demonstrated below:
import { Button } from "~/components/ui/button";
export default function Home() {
return (
<div>
<Button>Click me</Button>
</div>
);
}