You don't need expensive hosting to put a website online. With GitHub and Cloudflare Pages, you can host a static website completely free—with SSL, CDN, and excellent performance. Here's exactly how to do it.
What You'll Need
- A GitHub account (free)
- A Cloudflare account (free)
- A domain name (optional, ~$12/year)
- Your website files (HTML, CSS, JS)
Step 1: Create a GitHub Repository
First, let's get your files on GitHub.
- Go to github.com and sign in
- Click the + button → New repository
- Name it something like
my-website - Make it Public (required for free Cloudflare Pages)
- Turn on Add README
- Click Create repository
Step 2: Upload Your Files
You can either use Git from the command line or upload directly through the browser.
Option A: Using Git (Recommended)
# Navigate to your website folder
cd my-website
# Initialize git
git init
# Add all files
git add .
# Commit
git commit -m "Initial commit"
# Add your GitHub repo as remote
git remote add origin https://github.com/YOUR_USERNAME/my-website.git
# Push to GitHub
git branch -M main
git push -u origin main
Option B: Upload via Browser
- On your new repo page, click uploading an existing file
- Drag and drop your website files
- Click Commit changes
Step 3: Connect GitHub to Cloudflare Pages
Now let's deploy your site using Cloudflare Pages.
- Sign up or log in at dash.cloudflare.com
- In the left sidebar, click Workers & Pages
- Click Create application
- Select the Pages tab at the bottom
- Click Connect to Git
- Authorize Cloudflare to access your GitHub account
- Select your repository (e.g.,
my-website) - Click Begin setup
Configure Build Settings
For a simple static HTML site (no build process):
- Project name: your-project-name (this becomes your subdomain)
- Production branch: main
- Build command: leave empty
- Build output directory: leave empty (or
/if required)
Click Save and Deploy.
Wait 1-2 minutes for the deployment to complete. Once done, your site will be live at:
https://your-project-name.pages.dev
🎉 Congratulations! Your website is now online.
Step 4: Add a Custom Domain (Optional)
If you want your own domain (like mywebsite.com), keep reading. If the .pages.dev URL is fine for now, you can stop here.
4.1: Add Your Domain to Cloudflare
First, your domain needs to be managed by Cloudflare:
- In Cloudflare dashboard, click Add a Site
- Enter your domain name (e.g.,
mywebsite.com) - Select the Free plan
- Cloudflare will scan your existing DNS records
- It will give you two nameservers - copy these
4.2: Update Nameservers at Your Registrar
Go to wherever you bought your domain (Namecheap, GoDaddy, Porkbun, etc.) and update the nameservers to the ones Cloudflare gave you. This usually takes 5-30 minutes to propagate (sometimes up to 24 hours).
4.3: Add Custom Domain to Cloudflare Pages
Once your domain is active in Cloudflare:
- Go to Workers & Pages
- Click on your Pages project
- Go to the Custom domains tab
- Click Set up a custom domain
- Enter your domain (e.g.,
www.mywebsite.comormywebsite.com) - Click Continue
- Cloudflare will automatically configure the DNS records
- Click Activate domain
Cloudflare handles everything automatically—DNS records, SSL certificate, the works. Within a few minutes, your custom domain will be live.
Tip: Add both
mywebsite.comandwww.mywebsite.comas custom domains so both work.
Updating Your Site
Whenever you want to update your website, you have two options:
Option A: Using Git (Recommended)
# Make your changes locally, then:
git add .
git commit -m "Update: description of changes"
git push
Option B: Direct Upload on GitHub
- Go to your repository on GitHub
- Navigate to the file you want to update
- Click the pencil icon (Edit this file) to edit directly, OR
- Click Add file → Upload files to upload updated files
- Upload your updated HTML file (it will replace the existing file with the same name)
- Click Commit changes
Cloudflare Pages automatically detects the changes and redeploys your site within 1-2 minutes.
Troubleshooting
Common issues and fixes:
- 404 errors — Make sure you have an
index.htmlfile in the root of your repository - CSS not loading — Check your file paths (use relative paths like
css/style.css, not/css/style.css) - Custom domain not working — Wait for DNS propagation (can take up to 24 hours), check nameservers are updated
- Changes not showing — Hard refresh (
Ctrl+Shift+R) or clear browser cache - Build failed — For static HTML, make sure build command is empty
What You Get for Free
With this setup, you get:
- ✅ Free hosting (Cloudflare Pages — unlimited bandwidth)
- ✅ Free SSL certificate (HTTPS)
- ✅ Global CDN (Cloudflare's network)
- ✅ DDoS protection
- ✅ Fast page loads worldwide
- ✅ Automatic deployments when you push to GitHub
- ✅ Preview deployments for branches
The only cost is your domain name (~$12/year), and even that's optional if you're happy with the .pages.dev URL.
Wrapping Up
This is the same setup I use for this site and recommend to anyone building simple websites. It's reliable, fast, and costs almost nothing.
Got stuck somewhere? Drop me a message and I'll try to help.