In the modern web development landscape, hosting a static site has never been more straightforward. Whether you’re a seasoned developer or someone just starting out with HTML, CSS, and JavaScript, the ability to go from code to a live website in seconds is a game-changer. One of the most powerful and developer-friendly combinations available today is Cloudflare Pages static site hosting paired with a GitHub repository. In this article, we’ll walk through exactly how to set this up, why it matters, and how platforms like HTMLPUT make the entire process even simpler when you need instant results without the configuration overhead.
Why Choose Cloudflare Pages for Static Site Hosting?
Before diving into the step-by-step guide, it’s worth understanding what makes Cloudflare Pages static site hosting such an attractive option.
Cloudflare Pages is a JAMstack platform designed specifically for frontend developers. It integrates directly with your Git workflow, automatically building and deploying your site whenever you push changes. Here’s what makes it stand out:
- Global CDN: Cloudflare’s edge network spans over 330 cities worldwide, ensuring your static site loads incredibly fast for visitors no matter where they are.
- Automatic HTTPS: Every site gets a free SSL certificate, so your traffic is always encrypted.
- Unlimited bandwidth: There are no bandwidth caps on the free plan, which is a huge win for growing projects.
- Custom domain support: You can easily point your own domain to your Pages site.
- Instant rollbacks: If a deployment breaks something, you can revert to a previous version with a single click.
For many developers, the combination of GitHub and Cloudflare Pages represents the gold standard for deploying static sites. But it’s not the only option — and depending on your use case, you might want something even faster.
What You’ll Need to Get Started
To follow this guide, you’ll need:
- A GitHub account (free tier works perfectly)
- A static site project (even a single
index.htmlfile counts) - A Cloudflare account (free tier is sufficient)
That’s it. No server configuration, no FTP, no command-line wizardry required.
Step 1: Prepare Your Static Site on GitHub
Your static site can be as simple as a folder containing an index.html file, or as complex as a full single-page application built with React, Vue, or Svelte. Cloudflare Pages supports all major static site generators out of the box.
- Create a new repository on GitHub (it can be public or private — Cloudflare Pages works with both).
- Clone the repository to your local machine.
- Add your static files. For example, a minimal project might look like:
my-static-site/
├── index.html
├── style.css
└── script.js
- Commit and push your files to GitHub.
If you haven’t written any code yet and just want to test the process, you can create a simple index.html with some placeholder content. The key is to have a repository ready to link.
Step 2: Connect Cloudflare Pages to GitHub
Now we move into Cloudflare’s dashboard.
- Log in to your Cloudflare account and navigate to Pages from the left-hand menu.
- Click Create a project.
- Select Connect to Git and choose GitHub as your provider.
- You’ll be prompted to authorize Cloudflare Pages to access your GitHub repositories. Grant the necessary permissions.
Once authorized, you’ll see a list of your GitHub repositories. Select the one containing your static site.
Step 3: Configure Your Build Settings (or Skip Them)
This is where the “one-click” magic really shines. Cloudflare Pages will automatically detect the framework you’re using. For a plain HTML site, it will typically set:
- Build command: Leave blank (nothing to build)
- Build output directory: Leave as
/or set it to your root folder - Root directory (optional): If your site is in a subfolder, specify it here
If you’re using a static site generator like Hugo, Jekyll, or Next.js, Cloudflare will auto-detect the framework and suggest the correct build command. You can also set environment variables at this stage if needed.
Once your settings look correct, click Save and Deploy.
Within seconds, Cloudflare will clone your repository, process any build steps, and deploy your site to a pages.dev subdomain. You’ll see a live URL — something like your-project.pages.dev.
Step 4: Set Up One-Click Deployment from GitHub
This step is already taken care of by default. Every time you push new commits to your GitHub repository (specifically to the branch you selected during setup), Cloudflare Pages automatically triggers a new deployment.
This is the “one-click” (actually zero-click after the initial setup) deployment workflow:
- Make changes to your static site locally.
- Commit and push to GitHub.
- Cloudflare Pages detects the push, builds (if needed), and deploys.
- Your live site updates within seconds to minutes depending on the build time.
You can view the deployment history and status from the Cloudflare Pages dashboard. If something goes wrong, you can instantly roll back to any previous deployment.
Step 5: Add a Custom Domain
A pages.dev URL is fine for testing, but for production you’ll want your own domain.
- In your Cloudflare Pages project, go to Custom domains.
- Click Set up a custom domain.
- Enter your domain (e.g.,
example.comorwww.example.com). - Cloudflare will check your DNS configuration. If your domain is already on Cloudflare, it will add the required DNS records automatically. If not, you’ll need to update your nameservers or add the specific
CNAMErecord it provides.
Once the DNS propagates (usually within minutes), your static site will be accessible via your custom domain with full HTTPS support.
Comparing Cloudflare Pages with Other Static Hosting Options
While Cloudflare Pages static site hosting is excellent, it’s not the only way to deploy static sites. Let’s look at how it compares to other popular approaches.
Cloudflare Pages vs. Netlify
Netlify pioneered the Git-based deployment workflow and remains a strong competitor. Both offer similar features: global CDN, automatic HTTPS, and build integration. However, Cloudflare Pages has an edge when it comes to bandwidth and request limits — Cloudflare’s free plan is more generous. Netlify, on the other hand, has a richer ecosystem of serverless functions and form handling out of the box.
Cloudflare Pages vs. Vercel
Vercel is optimized for frontend frameworks like Next.js. If you’re building a heavy JavaScript application, Vercel offers deeper framework integration. Cloudflare Pages is more general-purpose and tends to perform better for plain static sites and sites built with simpler generators.
Cloudflare Pages vs. HTMLPUT
For developers who need the absolute fastest path from code to a live URL — without even setting up a GitHub repository or configuring a build pipeline — HTMLPUT offers a refreshingly simple alternative. Instead of connecting to Git and configuring Cloudflare, you can simply paste your HTML, publish instantly, and get a live URL backed by Cloudflare’s CDN.
If you’re prototyping, sharing a quick demo, or just want to host a small static page without any friction, HTMLPUT eliminates the setup entirely. For more advanced projects with continuous deployment from Git, Cloudflare Pages is the better fit. Both services use Cloudflare’s global network, but they cater to different workflows.
Advanced Tips for Cloudflare Pages
Once your site is live, here are a few ways to get even more out of Cloudflare Pages static site hosting:
Enable Password Protection
If your site is in development or meant for a limited audience, Cloudflare Pages allows you to add basic authentication. In the project settings, you can enable Cloudflare Access to protect your site with a username and password — no code changes required.
Use Redirect Rules
You can configure redirects directly in Cloudflare Pages. This is useful for moving old URLs to new ones or enforcing www vs. non-www conventions. Just add a _redirects file to your build output directory.
Optimize for Performance with Cloudflare CDN
Cloudflare Pages automatically caches your static assets on the global CDN. You can further optimize by setting custom cache rules using Cloudflare’s caching features. For example, you can cache images and CSS files for longer periods while keeping your HTML fresh.
Integrate with Cloudflare Workers
For dynamic functionality (like form submissions or API proxying), you can combine Cloudflare Pages with Cloudflare Workers. Workers run at the edge and can handle server-side logic without requiring a traditional backend.
Add a Custom 404 Page
Cloudflare Pages respects the 404.html file in your build output directory. Simply add a custom 404 page to your project, and it will be served automatically when visitors hit a broken link.
Common Pitfalls and How to Avoid Them
Even with a straightforward setup, there are a few things that can trip you up:
- Build command not found: If you’re using a static site generator, make sure the build tool is listed in your
devDependenciesinpackage.json. Cloudflare Pages installs dependencies automatically, but it needs to know what to install. - Incorrect output directory: If your site deploys but shows a blank page, double-check the build output directory. For example, if you’re using Hugo, the output directory is
public. For Next.js static export, it’sout. - Repository permissions: If Cloudflare Pages can’t access your repository, check the GitHub authorization settings. You may need to re-authenticate or update the repository access scope.
Final Thoughts
Cloudflare Pages static site hosting combined with GitHub offers one of the most elegant and powerful workflows for deploying static websites. It’s fast, free, scalable, and backed by one of the best content delivery networks in the world. Whether you’re launching a personal portfolio, a documentation site, or a marketing landing page, this setup gives you everything you need with minimal effort.
That said, simplicity comes in different forms. If you want a hosting experience that skips the Git setup and lets you publish straight from a text area, platforms like HTMLPUT are worth exploring. And if you’re looking for more tips and comparisons, the HTMLPUT blog covers a wide range of static hosting strategies and deployment workflows.
The beauty of the modern static web is that you have choices. Whether you prefer a full CI/CD pipeline or a one-click instant publish, there’s a solution that fits your style. Cloudflare Pages gives you the former with an incredibly smooth developer experience. Give it a try with your next project — you’ll be surprised how fast you can go from an idea to a live site.