How to Host a Static Website for Free with GitHub Pages
Posted on September 23, 2025 • 7 min read • 1,431 wordsA guide to hosting a static website for free with GitHub Pages, step by step.

.github.io domain, supports custom domains, and has built-in HTTPS.USERNAME.github.io for a user or organization site, or a generic repository for a project site.README.md or index.html.Before deploying a static site with GitHub Pages, you need to configure the repository. Here’s how:
If you don’t yet have a GitHub account:
Go to https://github.com/new to create a new repository:
| Site Type | Repository Name | Public Site URL |
|---|---|---|
| User/Organization Site | USERNAME.github.io | https://USERNAME.github.io/ |
| Project Site | Any name, e.g. my-project | https://USERNAME.github.io/my-project/ |
💡 For personal sites, the repository must match exactly
USERNAME.github.io.
Two options:
README.md or a simple index.html (e.g., Hello World!)git clone, add your static files, and push them.Minimal example of index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>My First GitHub Pages Site</title>
</head>
<body>
<h1>Hello GitHub Pages!</h1>
</body>
</html>GitHub Pages works without Actions if you’re only deploying simple static files.
However, it is highly recommended to enable GitHub Actions if:
npm run build, hugo, etc.) on each change..github/workflows/.Example file:
.github/workflows/deploy.yml
📄 .github/workflows/deploy.yml
name: Deploy static site to GitHub Pages
on:
push:
branches:
- main # Trigger on every push to main
permissions:
contents: write # Required to publish to gh-pages
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install dependencies
run: npm ci
- name: Build the site
run: npm run build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist # Replace with ./public if neededSuitable for modern stacks like Astro, Vite, static React, etc.
Automatically deploys thedist/folder on every push tomain.
📄 .github/workflows/deploy.yml
name: Deploy Hugo site to GitHub Pages
on:
push:
branches:
- main # Trigger on each push to main
permissions:
contents: write # Required to push to gh-pages
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: '0.124.1' # Specify your Hugo version
- name: Build Hugo site
run: hugo --minify
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./publicThis workflow automatically builds your Hugo site and publishes the
public/folder to thegh-pagesbranch.
No SSH key setup is required, the GitHub token is sufficient.
If you’re building a blog with Hugo, you can create a GitHub Action that:
hugo command to generate the static site,gh-pages branch.This allows for automatic deployment on every git push.
| Step | Required Action |
|---|---|
| GitHub Account | Create an account on github.com |
| Site Type | USERNAME.github.io or custom repo name |
| Initial Content | Add index.html, README.md, etc. |
| Enable GitHub Actions | Ensure actions are allowed in repository settings |
| Ready for Pages | Enable GitHub Pages under Settings > Pages |
Once your repository is ready and configured, here’s how to publish your static site using GitHub Pages:
Use this command in your terminal:
git clone https://github.com/USERNAME/USERNAME.github.ioReplace
USERNAMEwith your actual GitHub username.
This structure is used for a user or organization site.
For a project site, use:
git clone https://github.com/USERNAME/project-nameReplace
project-namewith your actual repository name.
Inside the cloned directory, add your site content:
index.htmlstyle.css)script.js)Typical structure:
my-site/
├── index.html
├── style.css
├── script.js
└── img/
└── logo.pngOnce your files are added, run:
git add --all
git commit -m "Initial commit"
git push origin mainIf your default branch is
master, use:git push origin master
Deploy from a branchmain (or master)/ (root) if your files are in the rootA success message will show the URL of your site.
| Site Type | Auto-generated URL |
|---|---|
| User Site | https://USERNAME.github.io/ |
| Project Site | https://USERNAME.github.io/project-name/ |
Future changes will appear at this URL after each
git push.
Note: it may take up to 10 minutes for the first deployment to appear.
If changes don’t show, try clearing your browser cache.
GitHub Pages supports Jekyll, a popular static site generator based on Ruby and Markdown. It automatically converts .md files to HTML.
📚 Reference: Jekyll – Wikipedia, Kinsta – GitHub Pages Guide
If you prefer Hugo, Astro, Gatsby, or others:
dist/ or public/gh-pages).nojekyll file to the root to disable Jekyll processingYou can automate this with GitHub Actions.
📚 Reference: GitHub Docs – Disabling Jekyll
GitHub Pages offers built-in themes that can be enabled via the interface or _config.yml.
You can also:
📚 Reference: GitHub Pages, Kinsta
You can link a personal domain easily:
A or CNAME) with your domain providerGitHub Pages enables HTTPS via Let’s Encrypt automatically.
📚 Reference: GitHub Docs – Custom Domains, DEV.to, LinkedIn
| Objective | GitHub Pages (Free) | Main Limitations |
|---|---|---|
| Static site (HTML/CSS/JS) | ✅ Very easy to deploy | ❌ No dynamic backend |
| Docs or wiki | ✅ Jekyll built-in | ❌ Not ideal for heavy content or traffic |
| Custom domain & HTTPS | ✅ Native support | – |
| CI/CD integration via GitHub Actions | ✅ Auto-deploy on push | – |
| Forms or dynamic features | ❌ Needs third-party services (e.g. Formspree) | ❌ No PHP or server-side support |
GitHub Pages is a free, reliable, and easy-to-use solution for hosting static websites. It’s ideal for portfolios, personal blogs, project documentation, and simple landing pages.
With native Jekyll support, GitHub Actions integration, and easy custom domain setup, it’s a great entry point to publish your web projects with zero cost.
For advanced use cases (backend, databases, dynamic content), consider using AWS S3, Netlify, or Vercel.