Installation
Install Tailwind CSS with Symfony
Setting up Tailwind CSS in a Symfony project.

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.
Terminalsymfony new my_project_directory --webappcd my_project_directoryInstall Webpack Encore
Install
Webpack Encorein a Symfony application.Terminalcomposer require symfony/webpack-encore-bundlenpm installInstall Tailwind CSS
Install
tailwindcssand its peer dependencies via npm, and create yourtailwind.config.jsfile.Terminalnpm install -D tailwindcss postcss autoprefixer postcss-loadernpx tailwindcss initAdding plugins to your PostCSS configuration
Create
postcss.config.jsfile and add the plugins.postcss.config.jsmodule.exports = { plugins: { tailwindcss: {}, autoprefixer: {}, } };Enable PostCSSLoader in your Webpack Encore configuration.
In your
webpack.config.jsfile, add its lines.webpack.config.jsconst 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();Configure your template paths
Add the paths to all of your template files in your
tailwind.config.jsfile.tailwind.config.jsmodule.exports = { content: [ "./assets/**/*.js", "./src/**/*.php", "./templates/**/*.html.twig" ], theme: { extend: {}, }, plugins: [], }Add the Tailwind directives to your CSS
Add the
@tailwinddirectives for each of Tailwind’s layers to your./assets/styles/app.cssfile.app.css@tailwind base; @tailwind components; @tailwind utilities;Start your build process
Run your build process with
npm run watch.Terminalnpm run watchStart 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>

