1

I have next.js with tailwind CSS installed. I configured everything accordingly to the instructions. All codes are below.

_app.js

import '../styles/index.css';

function MyApp({ Component, pageProps }) {
  return <Component {...pageProps} />
}

export default MyApp

tailwind.config.js

module.exports = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [],
}

postcss.config.js

module.exports = {
    plugins: ["tailwindcss"],
}

index.js

import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'

export default function Home() {
  return (
    <div className={styles.container}>
      <Head>
        <title>Create Next App</title>
        <meta name="description" content="Generated by create next app" />
        <link rel="icon" href="/favicon.ico" />
      </Head>

      
    </div>
  )
}

index.css

@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';

When I look up on index.css for any changes from browser (I use chrome) it stays the same. I'm not sure what's wrong.

2
  • Please Provide all code, maybe index.js from pages folder ? Commented Dec 31, 2021 at 12:09
  • Added index.js file Commented Dec 31, 2021 at 12:13

2 Answers 2

1

Firstly make sure that You installed tailwindcss with next.js properly. Here you have reference to docs


Then Just use it, example index.js page.

import Head from "next/head";

export default function Home() {
  return (
    <div>
      <Head>
        <title>Create Next App</title>
        <meta name="description" content="Generated by create next app" />
        <link rel="icon" href="/favicon.ico" />
      </Head>

      <div className="flex items-center justify-center h-screen flex-col gap-5">
        <h1 className="text-3xl text-red-500 font-semibold">Tailwind CSS</h1>
      </div>
    </div>
  );
}

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

5 Comments

I installed everything correctly.
@QI10 So try my code in action and everything should work as it should ;-) Good Luck! Best Regards!
I tried, but it didn't work.
Found the issue, it was related with tailwind.config.js. Thanks!
You 're Welcome Best regards !
0

on tailwind.config.js make sure that in content include the extensions

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./components/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.