Installation
Setting up Tailwind CSS in a Gatsby project.
Start by creating a new Gatsby project if you don’t have one set up already. The most common approach is to use Gatsby CLI.
gatsby new my-projectcd my-projectUsing npm, install @tailwindcss/postcss, its peer dependencies, and gatsby-plugin-postcss.
npm install @tailwindcss/postcss tailwindcss postcss gatsby-plugin-postcssIn your gatsby-config.js file, enable gatsby-plugin-postcss. See the plugin's documentation for more information.
module.exports = { plugins: [ 'gatsby-plugin-postcss', // ... ],}Create a postcss.config.js file in the root of your project and add the @tailwindcss/postcss plugin to your PostCSS configuration.
module.exports = { plugins: { "@tailwindcss/postcss": {}, },};Create a ./src/styles/global.css file and add an @import for Tailwind CSS.
@import "tailwindcss";Create a gatsby-browser.js file at the root of your project if it doesn’t already exist, and import your newly-created ./src/styles/global.css file.
import './src/styles/global.css';Run your build process with gatsby develop.
gatsby developStart using Tailwind’s utility classes to style your content.
export default function IndexPage() { return ( <Layout> <h1 className="text-3xl font-bold underline"> Hello world! </h1> </Layout> )}