March 30, 2025 • Django
Tailwind CSS 4 brings a streamlined installation process for Django projects. This guide walks you through setting up Tailwind CSS 4 with Django, based on practical implementation across multiple projects. I've refined this process to be as straightforward as possible.
This is for information only. Please remember to do your own research and backup your database before attempting to install anything new.
Thanks, for sharing:
First, create the necessary file structure in your Django project:
static
folder, create an output.css
filesrc
folder with an input.css
fileYour structure should look like this:
static/
├── css/
│ └── output.css
└── src/
└── input.css
Add the following to your input.css
file:
@import "tailwindcss";
That's it! No additional configuration required for Tailwind 4.
In your base.html
file, add these lines to the <head>
section:
{% load static %}
<!-- CSS style links -->
<link href="{% static 'css/style.css' %}" rel="stylesheet">
<link href="{% static 'css/output.css' %}" rel="stylesheet">
Important: Include {% load static %}
at the very top of your base.html file and all template files that use CSS or images. Any file using static files needs this tag at the top, after any {% extends 'base.html' %}
tag.
Install Tailwind CSS according to the official instructions:
npm install tailwindcss @tailwindcss/cli
During development, use the watch command to automatically rebuild CSS when changes are made:
npx @tailwindcss/cli -i static/src/input.css -o static/css/output.css --watch
Before deploying to production, build the optimised version:
npm run build
Note: You only need to upload the output.css
file to production. Other generated files like package.json
do not need to be uploaded to your hosting/production site.
Create a package.json
file in your project root with the following content (update as needed for your project):
{
"dependencies": {
"@tailwindcss/cli": "^4.0.12",
"tailwindcss": "^4.0.12"
},
"scripts": {
"build": "tailwindcss -i static/src/input.css -o static/css/output.css",
"watch": "tailwindcss -i static/src/input.css -o static/css/output.css --watch"
},
"keywords": [
"django",
"tailwindcss",
"web development"
],
"author": "YOUR NAME",
"license": "ISC",
"description": "A Django project using Tailwind CSS 4"
}
Note about package.json fields:
This step is crucial! After building your CSS, always run Django's collectstatic command:
python3 manage.py collectstatic
You always get asked if you are sure - to avoid that question (if you really are sure) add --noinput on the end.
If your site appears unstyled (with no CSS applied), it's often because the collectstatic command wasn't run. This is a frequent oversight even for experienced developers.
Tailwind CSS 4 is now successfully installed in your Django project. This streamlined process eliminates the need for a configuration file, making it faster to implement than previous versions.
If you need help with Django MVP development or technical assistance setting up your project, I'm here to help! As a Tech VA specialising in MVP development and technical marketing systems, I can guide you through the entire process from concept to launch.
This guide was created by Diane Corriette
Need help with your MVP or technical marketing? Get in touch.
Thanks, for sharing: