UndieGravity LogoUndiegravity

Host an HTML Website for Free on GitHub Pages

Publish an HTML template on GitHub Pages for free: create a repository, turn on Pages, add a custom domain with HTTPS, and know the size and usage limits.

By UndieGravity, , 1 min read

GitHub Pages serves static files (HTML, CSS, JavaScript, and images) straight from a repository, for free. It is a great home for a portfolio, a project page, or a one page site built from an HTML template.

1. Put the site in a repository

  1. Create a new public repository on GitHub.
  2. Upload your template files with Add file, Upload files, or push them with Git.
  3. Make sure index.html is in the root of the repository (or in a docs folder).

2. Turn on Pages

  1. Open the repository's Settings, Pages.
  2. Under Build and deployment, choose Deploy from a branch.
  3. Select the main branch and the / (root) folder, then save.

After a minute your site is live at https://USERNAME.github.io/REPOSITORY/. A repository named USERNAME.github.io is published at the root address instead; each account gets one of those.

3. Use relative paths

Because project sites live under /REPOSITORY/, a link to /style.css points at the wrong place. Use relative paths such as style.css or ./images/photo.webp, and the site works both locally and on Pages.

4. Add a custom domain

  1. In Settings, Pages, enter your domain, for example www.example.com.
  2. At your registrar, add a CNAME record for www pointing to USERNAME.github.io.
  3. For the root domain, add the A records listed in GitHub's documentation.
  4. When the check passes, tick Enforce HTTPS.

Limits to know

  • Published sites can be at most 1 GB.
  • There is a soft bandwidth limit of 100 GB per month.
  • Deployments time out after 10 minutes.
  • GitHub's terms say Pages is not intended as free hosting for an online business or ecommerce store. For a shop, use a host built for it.

Next.js and React on Pages

Pages serves static files only. A React (Vite) build works as is. A Next.js site works with output: "export" and the right basePath; features that need a server, such as Server Actions, do not.

Keep reading

Deployment

Deploy a Next.js Site to Vercel in 10 Minutes

Step by step: push your Next.js project to GitHub, import it into Vercel, add environment variables, connect a custom domain, and know the Hobby plan limits.

, 2 min read

Deployment

Deploy HTML and Next.js Sites to Netlify

Deploy to Netlify by dragging a folder for HTML sites or connecting Git for Next.js and React. Build settings, forms without a backend, and free plan basics.

, 1 min read