GitHub Pages is a powerful tool for hosting static websites, and adding a custom subdomain (e.g., blog.example.com
) can give your site a professional touch.

Whether you're a beginner or an expert, this guide will walk you through the steps to successfully configure a subdomain for your GitHub Pages site.
Why Use a Custom Subdomain?
- Enhances branding and professionalism.
- Provides better SEO optimization.
- Allows multiple sites under one domain (e.g.,
docs.example.com
,portfolio.example.com
). - Offers flexibility in managing different projects.
Prerequisites
Before you start, ensure that:
- You have a GitHub Pages site already set up.
- You own a custom domain (e.g.,
example.com
). - You have access to your DNS settings via your domain registrar (e.g., Namecheap, Cloudflare, GoDaddy).
Step 1: Set Up GitHub Pages
- Open your GitHub repository.
- Go to Settings > Pages.
- Under Build and Deployment, select the correct branch (e.g.,
main
orgh-pages
). - Click Save and note the generated GitHub Pages URL (
yourusername.github.io
).
Step 2: Configure Your DNS Settings
To point your subdomain to GitHub Pages, follow these steps:
For a Subdomain (e.g., blog.example.com
):
Open your DNS settings with your domain registrar.
Add a CNAME record with the following details:
Type Name Value TTL CNAME blog your-github-username.github.io Auto
📌 Example: If your site is hosted at yourusername.github.io
, and you want blog.example.com
as your subdomain, your CNAME should point blog
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
(no file extension). - Inside the file, type your subdomain (e.g.,
blog.example.com
). - Commit and push the file to your repository.
Step 4: Verify and Enable HTTPS
- Wait for DNS propagation (this may take a few minutes to hours).
- Visit GitHub Settings > Pages to check if your subdomain is recognized.
- Enable Enforce HTTPS for security and better SEO performance.
Troubleshooting Tips
Issue: My Subdomain Isn't Working
✅ Ensure your CNAME record is correctly configured. ✅ Check if the CNAME file in your repository has the correct subdomain. ✅ Wait for DNS propagation (use DNS Checker to verify). ✅ Clear your browser cache and retry.
Issue: SSL Certificate Not Available
✅ Make sure you enabled Enforce HTTPS in GitHub Pages settings. ✅ Wait for GitHub to generate the SSL certificate (it can take a few hours). ✅ Remove any conflicting SSL settings from your domain registrar.
Conclusion
Setting up a custom subdomain on GitHub Pages is a straightforward process that enhances your website's professionalism and usability. By following these steps, you can easily configure a subdomain and optimize your GitHub Pages site for branding and SEO.
🚀 Now, try it out and let us know how it goes!