GitHub Pages: How to Convert a Temporary cdn.tailwindcss.com or cdn.jsdelivr.net-Based Tailwind Site to a Permanent GitHub Actions Workflow-Based Site
This guide will show you how to permanently set up Tailwind CSS for your static HTML site using a GitHub Actions workflow. It includes configuration and troubleshooting.
This guide assumes that you already have the following line of code in the <head> section of your HTML file, per the official CDN setup instructions.
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>This setup process automatically implements Classpresso ☕, a post-build Tool that makes Tailwind CSS rendering up to 50% faster! You can learn more about it on their GitHub repository.
The reason you would switch to a GitHub actions workflow-based approach isn't because CDN doesn't work. It's because it's not designed for production use:
-
Performance: The CDN version compiles Tailwind CSS in the browser every time the page loads, which is slow. A pre-built CSS file loads instantly.
-
Reliability: You're dependent on Cloudflare's CDN staying up. If it goes down, your styles break.
-
File size: The CDN version includes the entire Tailwind compiler (~70KB). A built CSS file with only the styles you actually use is much smaller (often <20KB after minification).
-
Production best practice: Pre-built assets are the standard for any real website or project you deploy.
In your index.html, find and remove:
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>Replace it with:
<link rel="stylesheet" href="./dist/output.css">This will load your own pre-built Tailwind CSS, which you'll generate in the next steps.
Starting at the root of your repository, you need these files/folders:
my-repo/
├──.github
│ └── workflows
│ └── build-css.yml
├── pages/
│ └── index.html
├── src/
│ └── input.css
├── dist/
│ └── output.css # (will be generated by workflow)
├── tailwind.config.js
└── package.json
Create a file called build-css.yml in the folder .github/workflows:
name: Build, Optimize with Classpresso, and Deploy
on:
push:
branches:
- main
jobs:
Build Tailwind CSS:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 24
- name: Install dependencies
run: npm install
- name: Build Tailwind CSS
run: npx tailwindcss -i ./src/input.css -o ./dist/output.css
- name: Commit and push
run: |
git config user.email "action@github.com"
git config user.name "GitHub Action"
git add dist/output.css
git commit -m "Build CSS" || echo "No changes to commit"
git push || echo "Nothing to push"
Build Webpage and Deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 24
- run: npm install
# Build your static site
- name: Copy pages to public "dist" folder
uses: canastro/copy-file-action@master
with:
source: pages/.
target: dist/
flags: '-r'
- name: Ensure writable dist
run: sudo chown -R $USER:$USER dist
# Optimize classes in built HTML and CSS
- name: Optimize HTML with Classpresso
run: npx classpresso optimize --dir dist
# Deploy to GitHub Pages
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
user_name: 'GitHub-Actions Deploy [bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
Create a file called input.css in the src folder:
@tailwind base;
@tailwind components;
@tailwind utilities;Create a file called tailwind.config.js at the root of your repository:
module.exports = {
content: [
"./**/*.html",
],
theme: {
extend: {},
},
plugins: [],
}Create a file called package.json at the root of your repository:
{
"name": "berkeley-build-guild-website",
"version": "1.0.0",
"devDependencies": {
"autoprefixer": "^10.0.0",
"classpresso": "^1.7.2",
"postcss": "^8.0.0",
"tailwindcss": "^3.0.0"
}
}- Go to Settings > Pages in your repo.
- Under
Build and deployment, set the source toGitHub Actions. - Make a commit to trigger the workflow to build the website.
If the live website doesn't update right away, try waiting a minute and then refreshing the webpage. It can take a little while for GitHub to build the website.
git add .
git commit -m "Set up Tailwind workflow build"
git pushOtherwise, you can use GitHub's web interface to create/edit files and commit changes.
You now have a permanent, version-controlled Tailwind setup. No more CDN!
-
No styles?
- Make sure
dist/output.cssexists and is large (not empty). - Hard refresh your page (Ctrl+Shift+R).
- Check the "Build, Optimize with Classpresso, and Deploy" workflow logs for errors.
- Make sure
-
Classes not working?
- Confirm your
tailwind.config.jshas the rightcontentglobs. - Confirm
src/input.cssis in the correct location and not empty.
- Confirm your
-
Workflow errors?
- Ensure all files are in the repo.
- Make sure the
package.jsonis valid JSON (use the code provided above).