How to Use a Custom Domain for a GitHub Pages Site
If your site is hosted on GitHub Pages, you can use your own domain
(for example, blog.example.com) instead of the default
username.github.io. This guide walks through the full
setup with the safest path and common fixes.
Official reference: Configuring a custom domain for your GitHub Pages site.
1) Decide your domain style
-
Apex/root domain:
example.com(no subdomain) -
Subdomain:
www.example.comorblog.example.com
Subdomains are usually easier to configure and maintain, but both options work with GitHub Pages.
2) Add your domain in GitHub Pages settings
In your repository (GitHub Docs: Managing a custom domain for your GitHub Pages site):
- Go to Settings → Pages.
- Under Custom domain, enter your domain and save.
-
Wait for GitHub to create/update the
CNAMEfile in your repo.
3) Configure DNS records at your domain provider
At your DNS provider (Cloudflare, Namecheap, GoDaddy, etc.):
-
For
www.example.comorblog.example.com, create aCNAMErecord pointing tousername.github.io. -
For root domain
example.com, useArecords to GitHub Pages IPs.
185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153
If your DNS provider supports ALIAS or
ANAME for root domains, you can use that instead.
4) Enable HTTPS
Back in GitHub Pages settings, turn on Enforce HTTPS after certificate provisioning is complete. This can take a little while after DNS starts resolving.
5) Verify the setup
For better security, verify domain ownership in GitHub: Verifying your custom domain for GitHub Pages.
-
Confirm your repo has a
CNAMEfile with exactly your domain. - Open your domain in a browser and test
https://. - Check both non-www and www behavior if you use redirects.
Common issues and fixes
GitHub maintains an official checklist for DNS and HTTPS issues: Troubleshooting custom domains and GitHub Pages.
- Domain not working yet: DNS propagation can take minutes to 48 hours.
-
404 on custom domain: check that your DNS target
and
CNAMEfile value match exactly. - HTTPS unavailable: wait for DNS to fully resolve, then recheck the Pages settings.
-
Wrong repo type: user/organization sites should be
in
username.github.io; project sites have different URL behavior.
Once this is done, your site will load from your own domain while still being hosted for free on GitHub Pages.