GitHub Pages- How to Create Your Own Website for Free
What GitHub Pages Actually Is
GitHub Pages is free static website hosting built into GitHub. You push code to a repository, and GitHub serves it as a website. No servers to maintain, no hosting bills, no configuration headaches.
It works for personal blogs, project documentation, portfolios, and landing pages. If you need dynamic features like a database or server-side processing, this isn't your solution.
What You Get for Free
- Unlimited bandwidth
- Unlimited projects (one per repository)
- Custom domain support
- SSL/HTTPS automatically
- Jekyll site generator built-in
The only real cost is your time to set it up.
What You Don't Get
GitHub Pages is static only. No PHP, no databases, no server-side code. Your site must be pure HTML, CSS, and JavaScript. If that sounds limiting, you probably don't need GitHub Pages.
Prerequisites
- A GitHub account (free tier works fine)
- Basic Git knowledge or willingness to learn
- Something to put on the site
That's it. No credit card, no paid tools needed.
How to Set Up Your First GitHub Pages Site
Step 1: Create a Repository
Go to GitHub and click New Repository. Name it exactly like this:
username.github.io
Replace "username" with your actual GitHub username. This naming convention tells GitHub to automatically serve the repo as a website.
Step 2: Upload Your Files
You need an index.html file at minimum. You can:
- Click "Add file" β "Create new file" β name it
index.html - Clone the repo to your computer and push files normally
- Use GitHub's web editor for quick edits
Here's the bare minimum to get started:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Site</title>
</head>
<body>
<h1>Hello, world</h1>
<p>This is my free website.</p>
</body>
</html>
Step 3: Enable GitHub Pages
Go to your repository Settings β scroll to Pages.
Under "Source," select:
- Branch: main
- Folder: / (root)
Click Save. Wait 1-2 minutes. Your site goes live at:
https://username.github.io
Adding a Custom Domain
Skip this if you're fine with the default .github.io URL.
Buying a Domain
Buy a domain from anywhereβNamecheap, Google Domains, Cloudflare. Doesn't matter. You'll spend around $10-15 per year.
Configuring DNS
Add these records at your domain registrar:
- A records: 185.199.108.153, 185.199.109.153, 185.199.110.153, 185.199.111.153
- CNAME: www β
username.github.io
Connecting to GitHub Pages
In your repo Settings β Pages β Custom domain, enter your domain name. Check Enforce HTTPS. GitHub handles the SSL certificate automatically through Let's Encrypt.
DNS changes take up to 48 hours to propagate, though it's usually faster.
Using Jekyll for Static Sites
Jekyll is a static site generator built into GitHub Pages. Instead of writing raw HTML for every page, you write content in Markdown and Jekyll converts it to HTML.
Jekyll is useful for blogs and documentation. If you're building a simple landing page, you don't need it.
Jekyll Quick Start
Create a file named _config.yml in your repo root:
title: My Site
description: What the site is about
theme: minima
Create a folder named _posts and add a file like 2024-01-15-welcome.md:
---
layout: post
title: "Welcome"
---
This is my first post. Jekyll converts this Markdown to HTML.
GitHub automatically builds your Jekyll site when you push. No local build process needed.
GitHub Pages vs Alternatives
| Feature | GitHub Pages | Netlify | Vercel |
|---|---|---|---|
| Cost | Free | Free tier available | Free tier available |
| Custom domain | β | β | β |
| Auto HTTPS | β | β | β |
| Built-in CI/CD | β | β | β |
| Server-side rendering | β | β | β (with extra config) |
| Form handling | β | β | β |
| Ease of setup | Moderate | Easy | Easy |
GitHub Pages wins for pure simplicity and cost. If you need forms or server-side features, look at Netlify.
Common Problems and Fixes
Site Not Updating
GitHub Pages builds can take 2-3 minutes. If you pushed and nothing changed, wait before panicking. Also check that your source branch and folder are correct in Settings.
404 Errors on Internal Pages
GitHub Pages doesn't support clean URLs by default. Use index.html extensions or enable Jekyll's permalink settings.
Theme Not Loading
If you're using a Jekyll theme and it looks broken, check your _config.yml for syntax errors. GitHub Pages shows build errors in the Actions tab.
Who Should Use This
Use GitHub Pages if:
- You want a free, reliable static site
- You're comfortable with Git
- You don't need databases or dynamic features
Don't bother if:
- You need server-side processing
- You want a drag-and-drop website builder
- You're not willing to learn basic Git
The Bottom Line
GitHub Pages is free, fast, and reliable. It works exactly as advertised. The setup takes 15-30 minutes if you're starting from scratch. Your site will load fast, stay online, and cost you nothing.
The main limitation is that you're building a static site. If that's what you need, there's no reason to pay for hosting.