1. Create your project

    Start by creating a new Symfony project if you don’t have one set up already. The most common approach is to use the Symfony Installer.

    Terminal
    symfony new my_project_directory --webappcd my_project_directory
  2. Install Webpack Encore

    Install Webpack Encore in a Symfony application.

    Terminal
    composer require symfony/webpack-encore-bundlenpm install
  3. Install Tailwind CSS

    Install tailwindcss and its peer dependencies via npm, and create your tailwind.config.js file.

    Terminal
    npm install -D tailwindcss postcss autoprefixer postcss-loadernpx tailwindcss init
  4. Adding plugins to your PostCSS configuration

    Create postcss.config.js file and add the plugins.

    postcss.config.js
    module.exports = {
      plugins: {
        tailwindcss: {},
        autoprefixer: {},
      }
    };
    
  5. Enable PostCSSLoader in your Webpack Encore configuration.

    In your webpack.config.js file, add its lines.

    webpack.config.js
    const Encore = require('@symfony/webpack-encore');
    
    if (!Encore.isRuntimeEnvironmentConfigured()) {
        Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
    }
    
    Encore
    
        ...
    
        .enablePostCssLoader((options) => {
            options.postcssOptions = {
                config: './postcss.config.js'
            };
        })
    
    ;
    
    module.exports = Encore.getWebpackConfig();
    
  6. Configure your template paths

    Add the paths to all of your template files in your tailwind.config.js file.

    tailwind.config.js
    module.exports = {
      content: [
        "./assets/**/*.js",
        "./src/**/*.php",
        "./templates/**/*.html.twig"
      ],
      theme: {
        extend: {},
      },
      plugins: [],
    }
    
  7. Add the Tailwind directives to your CSS

    Add the @tailwind directives for each of Tailwind’s layers to your ./assets/styles/app.css file.

    app.css
    @tailwind base;
    @tailwind components;
    @tailwind utilities;
  8. Start your build process

    Run your build process with npm run watch.

    Terminal
    npm run watch
  9. Start using Tailwind in your project

    Make sure your compiled CSS is included in the <head> then start using Tailwind’s utility classes to style your content.

    base.html.twig
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="UTF-8">
      <title>{% block title %}Welcome!{% endblock %}</title>
      <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>⚫️</text></svg>">
      {# Run `composer require symfony/webpack-encore-bundle` to start using Symfony UX #}
      {% block stylesheets %}
          {{ encore_entry_link_tags('app') }}
      {% endblock %}
    
      {% block javascripts %}
          {{ encore_entry_script_tags('app') }}
      {% endblock %}
    </head>
    <body>
      <h1 class="text-3xl font-bold underline">
        Hello world!
      </h1>
    {% block body %}{% endblock %}
    </body>
    </html>