cruntrix
BUILDTUTORIAL

How to host a static site on Cloudflare Pages for free

No server, no monthly bill, and every update goes live when you push to GitHub. How to set up a blog, portfolio or small business site on Cloudflare Pages, step by step.

Research-based: specs + published reviews

Illustration of a terminal window showing a site being built and deployed

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

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

  1. In the Cloudflare dashboard, open Workers & Pages and click Create application.
  2. 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.)
  3. Choose Import an existing Git repository and click Connect GitHub.
  4. GitHub asks you to install the Cloudflare Workers and Pages app. Choose Only select repositories, pick your site’s repository, and approve.
  5. 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.

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:

Two more tricks worth knowing:

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.

SOURCES

Nate ArdenEditor of Cruntrix. Edits every article before it goes up and writes the Build section.