Adding a custom domain to your GitHub Pages site gives it a professional look and enhances your brand identity.

This guide will help you configure a custom domain (e.g., www.example.com
) for your GitHub Pages website.
Why Use a Custom Domain?
- Improves branding and credibility.
- Enhances SEO rankings.
- Allows multiple projects under one domain (e.g.,
blog.example.com
,docs.example.com
). - Provides better control over website URLs.
Prerequisites
Before you proceed, ensure you have:
- A GitHub Pages site already set up.
- A custom domain purchased from a registrar (e.g., Namecheap, GoDaddy, Cloudflare).
- Access to your DNS settings via your domain provider.
Step 1: Configure GitHub Pages
- Open your GitHub repository.
- Navigate to Settings > Pages.
- Under Custom domain, enter your domain name (e.g.,
www.example.com
). - Click Save, and GitHub will suggest DNS records.
Step 2: Update DNS Records
To connect your domain to GitHub Pages, configure your DNS records with your registrar.
For Root Domain (example.com):
Add A Records pointing to GitHub Pages IP addresses:
Type Name Value TTL A @ 185.199.108.153 Auto A @ 185.199.109.153 Auto A @ 185.199.110.153 Auto A @ 185.199.111.153 Auto
For Subdomain (www.example.com):
Add a CNAME record:
Type Name Value TTL CNAME www your-github-username.github.io Auto
📌 Example: If your site is hosted at yourusername.github.io
, your CNAME should point www
to yourusername.github.io
.
Step 3: Add a CNAME
File in Your GitHub Repository
- In your GitHub repository, go to the root directory.
- Create a new file named
CNAME
. - Inside the file, add your custom domain (e.g.,
www.example.com
). - Commit and push the file.
Step 4: Enable HTTPS (Optional but Recommended)
- Go to GitHub Settings > Pages.
- Check the Enforce HTTPS box.
- GitHub will generate an SSL certificate (may take some time).
Troubleshooting Tips
Issue: Domain Not Working
✅ Double-check DNS records and propagation status (DNS Checker). ✅ Ensure the CNAME file in your repository is correct. ✅ Allow some time for DNS propagation.
Issue: SSL Certificate Not Available
✅ Enable Enforce HTTPS in GitHub Pages settings. ✅ Wait for GitHub to generate the certificate. ✅ Remove any conflicting SSL settings from your registrar.
Conclusion
Adding a custom domain to GitHub Pages is a simple yet essential step to enhance your website's professionalism and accessibility. Follow these steps, and your custom domain will be live in no time!
🚀 Try it out and elevate your GitHub Pages site today!