To pull in Tailwind for quick demos or just giving the framework a spin, grab the latest default configuration build via CDN:

Or if you’d like to pull in the base styles separate from the utility classes:

  1. <!-- Any of your own CSS would go here -->
  2. <link href="https://cdn.jsdelivr.net/npm/tailwindcss@0.7.4/dist/utilities.min.css" rel="stylesheet">

NPM

For most projects (and to take advantage of Tailwind’s customization features), you’ll want to install Tailwind via npm.

Tailwind is available on npm and can be installed using npm or Yarn.

Tailwind is configured almost entirely in plain JavaScript. To do this you’ll need to generate a Tailwind config file for your project. We recommend creating a tailwind.js file in your project’s root.

We’ve provided a CLI utility to do this easily:

Installation - 图2

Use the @tailwind directive to inject Tailwind’s preflight and utilities styles into your CSS.

To avoid specificity issues, we highly recommend structuring your main stylesheet like this:

  1. /**
  2. * This injects Tailwind's base styles, which is a combination of
  3. * Normalize.css and some additional base styles.
  4. *
  5. * You can see the styles here:
  6. * https://github.com/tailwindcss/tailwindcss/blob/master/css/preflight.css
  7. *
  8. * If using `postcss-import`, use this import instead:
  9. *
  10. * @import "tailwindcss/preflight";
  11. */
  12. @tailwind preflight;
  13. /**
  14. * This injects any component classes registered by plugins.
  15. *
  16. * If using `postcss-import`, use this import instead:
  17. *
  18. * @import "tailwindcss/components";
  19. */
  20. @tailwind components;
  21. /**
  22. * Here you would add any of your custom component classes; stuff that you'd
  23. * want loaded *before* the utilities so that the utilities could still
  24. *
  25. * Example:
  26. *
  27. * .btn { ... }
  28. * .form-input { ... }
  29. *
  30. * Or if using a preprocessor or `postcss-import`:
  31. *
  32. * @import "components/buttons";
  33. */
  34. /**
  35. * This injects all of Tailwind's utility classes, generated based on your
  36. * config file.
  37. *
  38. * If using `postcss-import`, use this import instead:
  39. *
  40. * @import "tailwindcss/utilities";
  41. */
  42. @tailwind utilities;
  43. /**
  44. * Here you would add any custom utilities you need that don't come out of the
  45. * box with Tailwind.
  46. *
  47. * Example :
  48. *
  49. * .bg-pattern-graph-paper { ... }
  50. * .skew-45 { ... }
  51. *
  52. * Or if using a preprocessor or `postcss-import`:
  53. *
  54. * @import "utilities/background-patterns";
  55. * @import "utilities/skew-transforms";
  56. */

Using Tailwind CLI

For simple projects or just giving Tailwind a spin, you can use the Tailwind CLI tool to process your CSS:

Use the npx tailwind help build command to learn more about the various CLI options.

Using Tailwind with PostCSS

For most projects, you’ll want to add Tailwind as a PostCSS plugin in your build chain.

We’ve included the Tailwind-specific instructions for a few popular tools below, but for instructions on getting started with PostCSS in general, see the .

Webpack

Add tailwindcss as a plugin in your postcss.config.js file, passing the path to your config file:

  1. var tailwindcss = require('tailwindcss');
  2. module.exports = {
  3. plugins: [
  4. // ...
  5. tailwindcss('./path/to/your/tailwind.js'),
  6. // ...
  7. ]
  8. }

Gulp

Add tailwindcss to the list of plugins you pass to gulp-postcss, passing the path to your config file:

Laravel Mix

If you’re writing your project in plain CSS, use Mix’s postCss method to process your CSS. Include tailwindcss as a plugin and pass the path to your config file:

  1. var tailwindcss = require('tailwindcss');
  2. tailwindcss('./path/to/your/tailwind.js'),
  3. ]);

If you’re using a preprocessor, use the options method to add tailwindcss as a PostCSS plugin:

  1. var tailwindcss = require('tailwindcss');
  2. mix.less('resources/less/app.less', 'public/css')
  3. .options({
  4. postCss: [
  5. tailwindcss('./path/to/your/tailwind.js'),
  6. ]
  7. });

Note for Sass users: Due to an unresolved issue with one of Mix’s dependencies, to use Sass with Tailwind you’ll need to disable processCssUrls:

  1. var tailwindcss = require('tailwindcss');
  2. mix.sass('resources/sass/app.scss', 'public/css')
  3. .options({
  4. processCssUrls: false,
  5. postCss: [ tailwindcss('./path/to/your/tailwind.js') ],
  6. });

For more information on what this feature does and the implications of disabling it, .

Webpack Encore

Create a postcss.config.js file, add tailwindcss as a plugin and pass the path to your config file:

Within webpack.config.js, create a style entry and enable the PostCSS loader.

  1. var Encore = require('@symfony/webpack-encore');
  2. Encore
  3. .setOutputPath('public/build/')
  4. .setPublicPath('/build')
  5. .addStyleEntry('app', './css/app.css')
  6. .enablePostCssLoader()
  7. ;
  8. module.exports = Encore.getWebpackConfig();

You can also pass options into the PostCSS loader by passing a callback, as per the :

  1. .enablePostCssLoader(function(options) {
  2. options.config = {
  3. path: 'config/postcss.config.js'
  4. };
  5. })
  1. Encore
  2. .enableSassLoader(function (options) {}, {
  3. resolveUrlLoader: false
  4. })

Brunch

Add to the list of processors you pass to , passing the path to your config file: