If your site doesn’t need logins or a shop, you probably don’t need a server, a database or a monthly hosting bill. A static site, made of plain HTML files, can be hosted free on Cloudflare Pages, with every change going live when you push it to GitHub. Here’s how to host a static site on Cloudflare Pages, from an empty account to your own domain.
What “static” means, and when it suits you
A static site is a folder of ready-made files (HTML, CSS, images) that the host sends to visitors as they are. There’s no database and no code running on a server when someone visits. That makes it fast, cheap and hard to hack.
It suits blogs, portfolios, documentation, landing pages and small business sites. It doesn’t suit sites where visitors log in, shop or post comments, unless you add those pieces with separate services. If you store the site’s images and backups elsewhere, see which cloud storage to use.
You can write the HTML by hand, or use a static site generator: a program that turns Markdown files and templates into finished pages. Hugo, Eleventy and Astro are popular, and a short script in Python or JavaScript works too.
What you need
- A GitHub account (free).
- A Cloudflare account (free).
- Your site’s files, or a generator project that builds them.
- Optionally, your own domain name.
Step 1: Put the site on GitHub
Create a new repository on GitHub (it can be private) and upload your project. If you use a generator, upload the source files, not the built output: Cloudflare will build it for you on every change.
Step 2: Create the Pages project
- In the Cloudflare dashboard, open Workers & Pages and click Create application.
- Make sure you’re creating a Pages project. On the current dashboard, look for the link “Looking to deploy Pages? Get started” near the bottom of the page. (The other options create a Worker, which is a different product.)
- Choose Import an existing Git repository and click Connect GitHub.
- GitHub asks you to install the Cloudflare Workers and Pages app. Choose Only select repositories, pick your site’s repository, and approve.
- Back in Cloudflare, select the repository and click Begin setup.
Step 3: Tell it how to build
This is the only part that needs thought.
- Production branch: usually
main. - Framework preset: pick your generator if it’s listed (Hugo, Astro, Eleventy and others are). For hand-written HTML or a custom script, choose None.
- Build command: the command that builds your site. For plain HTML files, leave it empty. For Hugo it’s
hugo; for Eleventy,npx @11ty/eleventy; for a project with apackage.json, usuallynpm run build. Cloudflare’s build environment includes Node.js, Python and other common tools. - Build output directory: the folder the build creates, such as
dist,publicor_site. For plain HTML, it’s the folder yourindex.htmlis in.
Click Save and Deploy. A minute or two later you get a live address like your-project.pages.dev.
Step 4: Every push goes live
From now on, each time you push a change to the main branch, Cloudflare rebuilds and publishes the site. Push to any other branch and you get a separate preview address, so you can check a change before it goes live. If something breaks, open the project’s Deployments list and roll back to an earlier version in one click.
Step 5: Add your own domain
In the project, open Custom domains and add your domain. If the domain’s DNS is already managed by Cloudflare, it sets everything up for you. If not, Cloudflare walks you through moving DNS over: you change your domain’s nameservers at the registrar where you bought it, and keep the registration there.
Useful extras
Two plain-text files in your output folder control a lot of behaviour:
_redirectssends old addresses to new ones, for example/old-post/ /new-post/ 301. It’s essential if you’re moving from another platform such as WordPress and want old links, and their search rankings, to keep working._headersadds HTTP headers, such as security headers or long cache times for images and fonts.
Two more tricks worth knowing:
- Hide the test address from Google by sending an
X-Robots-Tag: noindexheader on thepages.devaddress only, so only your real domain gets indexed. - Schedule posts by giving them a future date and having the build skip anything not yet due. A Cloudflare deploy hook (a secret URL that starts a fresh build) called once a day by a tiny scheduled Worker publishes them on time.
The same setup works for browser games, which are just files too; see how to build a browser game with AI.
The limits worth knowing
The free plan is generous for a static site: unlimited sites and bandwidth, but 500 builds a month per account and one build at a time. A few pushes a day stays well inside that. If you run several busy sites on one account, combine small changes into fewer pushes.
FAQ
Is Cloudflare Pages really free?
For a static site, yes. The free plan includes unlimited sites, requests and bandwidth. The main limits are 500 builds a month per account and one build at a time, which is plenty for a blog or portfolio.
Can I use it without GitHub?
Yes. Choose Direct Upload and drag in a folder of finished HTML files. You lose automatic builds on every push, but it's the quickest way to put a simple site online.
Do I need to move my domain to Cloudflare?
Not to use a subdomain like www, but the simplest setup, including the bare domain (example.com), is to let Cloudflare manage your domain's DNS. You keep the domain registered wherever you bought it.



