Material Tailwind with Next.js

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


Creating a Next.js Project

First, create a new Next.js project using the command below, it will create a new Next.js project with Tailwind CSS installed and configured.

For more details check the Next.js Official Documentation.

npx create-next-app@latest --tailwind
npx create-next-app@latest --tailwind

Install Material Tailwind

Once you have created your Next.js project, 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";

const config: Config = {
content: [
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
"./app/**/*.{js,ts,jsx,tsx,mdx}",
"./node_modules/@material-tailwind/react/**/*.{js,ts,jsx,tsx}"
],
theme: {...},
plugins: [mtConfig],
};

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

const config: Config = {
content: [
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
"./app/**/*.{js,ts,jsx,tsx,mdx}",
"./node_modules/@material-tailwind/react/**/*.{js,ts,jsx,tsx}"
],
theme: {...},
plugins: [mtConfig],
};

export default config;

Example

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

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

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

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