what i'll be going through is notes from the first link in the reference below.
before you go into this, let it be known: you DON'T need to setup tailwindcss configuration if you don't need to customize the original setup, which is very very well written and acocunts for 70-80% of most use cases. When you come across something you would like to change in tailwind, that is the time when you can come back and start configuring tailwind.
it processes your css into its css, after you've written it. that's what a postCSS plugin does (it's not _pre_CSS for instance, like SASS)
its like webpack or rollup, the compiler that powers most modern frameworks today (react, svelte, vue etc)
it allows you to do nice, modern stuff (like imports) and write beautiful code that your browser doesn't understand, and then squashes it into horribly ugly but fast code that your browser understands.
your framework of choice has to have postCSS installed.
with this npm init next-app
postcss.config.js file in your project rootlike this:
module.exports = {
plugins: ['tailwindcss', 'postcss-preset-env'],
}like this:
@tailwind base;
@tailwind components;
@tailwind utilities;this is very nextjs-specific, but the gist is: import your css file somewhere so that the styles get loaded when your project starts
the nextjs way to import global styles is to make a "first point of entry" file called "_app.js" in "/pages".
like this:
import '../styles/index.css'and because this is a first point of entry for the app, it is a React component, kinda like the root component in React apps.
add this to the same file:
export default function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}that essentially overrides nextjs's default app.js file more here and here
Component is whatever page nextjs passes through when you click on any page (a page is a file in your "/pages" folder. except "_app.js")
pageProps is what gets passed into your page component when it loads (if you don't get getInitialProps then there's nothing inside)
start using your tailwind-ified app!
try adding className="bg-red-300 hover:text-red-500" on one of your elements.
don't worry if you don't remember any of the classes, autocomplete will help you! and if that fails, check out the docs! the tailwind website has a big searchbar on top for a reason.
npm install tailwindcsstouch styles.css to make a style.css file@tailwind base;@tailwind components;@tailwind utilities; in your style.css filenpx tailwindcss build styles.css -o output.cssif you happen to have this plugin installed, disable it or don't install Tailwind CSS IntelliSense, either one works, only the html-css-class-completion plugin is more generic and works by reading everything in for your .css files, which can mean it may be better for your use case.
Tailwind CSS IntelliSense shows you the style when you hover over a tailwind class though, which is very helpful when you're just learning the ropes.
there are a lot of resources out there for setting up tailwind (because it's the new hotness right now as of date of publish)
tailwindcss + nextjs nextjs with tailwind already integrated tailwindcss + gatsbyjs tailwindcss + vuetify the main docss