Material Tailwind with Remix

Learn how to setup and install @material-tailwind/react with Remix.


Creating a Remix Project

First, create a new Remix project using the command below, it will create a new Remix project.

For more details check the Remix Official Documentation.

npx create-remix@latest
npx create-remix@latest

Install Tailwind CSS

Once you have created your Remix project, you need to install and configure Tailwind CSS by running the following command:

npm install -D tailwindcss postcss autoprefixer && npx tailwindcss init --ts -p
npm install -D tailwindcss postcss autoprefixer && npx tailwindcss init --ts -p

Configure Your Template Paths

Once you have installed Tailwind CSS, you need to configure your template paths in your tailwind.config.ts file.

import type { Config } from 'tailwindcss'

export default {
content: ["./app/**/*.{js,jsx,ts,tsx}"],
theme: {
extend: {},
},
plugins: [],
} satisfies Config
import type { Config } from 'tailwindcss'

export default {
content: ["./app/**/*.{js,jsx,ts,tsx}"],
theme: {
extend: {},
},
plugins: [],
} satisfies Config

Add Tailwind CSS Directives to CSS

Next, you need to add the Tailwind CSS directives to your CSS file. Create a ./app/tailwind.css file and add the @tailwind directives for each of Tailwind's layers.

@tailwind base;
@tailwind components;
@tailwind utilities;
@tailwind base;
@tailwind components;
@tailwind utilities;

Import CSS File

Next, you need to import the newly-created tailwind.css file in your ./app/root.tsx file.

import {
Links,
Meta,
Outlet,
Scripts,
ScrollRestoration,
} from "@remix-run/react";

import type { LinksFunction } from "@remix-run/node";
import stylesheet from "~/tailwind.css?url";

export const links: LinksFunction = () => [
{ rel: "stylesheet", href: stylesheet },
];

export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}

export default function App() {
return <Outlet />;
}
import {
Links,
Meta,
Outlet,
Scripts,
ScrollRestoration,
} from "@remix-run/react";

import type { LinksFunction } from "@remix-run/node";
import stylesheet from "~/tailwind.css?url";

export const links: LinksFunction = () => [
{ rel: "stylesheet", href: stylesheet },
];

export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}

export default function App() {
return <Outlet />;
}

Install Material Tailwind

Once you installed and configured Tailwind CSS, you need to install @material-tailwind/react by running the following command:

npm i @material-tailwind/react@beta
npm i @material-tailwind/react@beta

Add Plugin and Template Path

Once you installed @material-tailwind/react you need to add mtConfig and the template path to your tailwind.config.ts file.

import type { Config } from 'tailwindcss'
import { mtConfig } from "@material-tailwind/react";

export default {
content: [
"./app/**/*.{js,jsx,ts,tsx}",
"./node_modules/@material-tailwind/react/**/*.{js,ts,jsx,tsx}"
],
theme: {
extend: {},
},
plugins: [mtConfig],
} satisfies Config
import type { Config } from 'tailwindcss'
import { mtConfig } from "@material-tailwind/react";

export default {
content: [
"./app/**/*.{js,jsx,ts,tsx}",
"./node_modules/@material-tailwind/react/**/*.{js,ts,jsx,tsx}"
],
theme: {
extend: {},
},
plugins: [mtConfig],
} satisfies Config

Example

Now you're ready to use Material Tailwind components in your Remix project. Here's an example of how to use the Button component:

import { Button } from "@material-tailwind/react";

export default function Index() {
return <Button>Button</Button>
}
import { Button } from "@material-tailwind/react";

export default function Index() {
return <Button>Button</Button>
}