Domains

How to Use a Custom Domain on GitHub Pages

Pointing your own domain to GitHub Pages takes two steps: adding DNS records at your registrar and declaring the domain inside your repository settings.

Detailed shot of Ethernet cables connected to server ports highlighting technology infrastructure.

To use a custom domain with GitHub Pages you need to do two things: add the right DNS records at your registrar and declare the domain inside your GitHub repository settings. Once both sides match, GitHub automatically provisions a free HTTPS certificate via Let's Encrypt.

Before you start: subdomain vs. apex domain

GitHub Pages distinguishes between two types of custom domain:

  • Subdomain (www.yourdomain.com or blog.yourdomain.com): configured with a CNAME record.
  • Apex (root) domain (yourdomain.com with no prefix): cannot use a CNAME without breaking DNS standards. Configured with A records (or ALIAS/ANAME if your registrar supports them).

GitHub recommends setting up both — apex and www — and letting GitHub handle the automatic redirect between them.

Step 1 — Configure DNS records

Option A: subdomain (www or any other)

In your registrar's DNS panel, create a CNAME record:

Type Name Value TTL
CNAME www yourusername.github.io. 3600

Replace yourusername with your GitHub username or organization name. The trailing dot is optional but technically correct.

Option B: apex (root) domain

Create four A records pointing to GitHub Pages' IP addresses:

Type Name Value
A @ 185.199.108.153
A @ 185.199.109.153
A @ 185.199.110.153
A @ 185.199.111.153

All four IPs are valid simultaneously; GitHub load-balances across them. If your registrar doesn't allow multiple A records with the same name, add at least the first two.

Recommended setup (apex + www together)

For the best coverage, add all four A records for @ and the CNAME for www. GitHub will detect both and enable automatic redirects between the root and www — you choose which one is canonical in the repository settings.

Step 2 — Declare the domain in GitHub

  1. Go to your repository on GitHub.
  2. Click the Settings tab.
  3. In the left sidebar, select Pages.
  4. In the Custom domain field, type your domain (e.g. www.yourdomain.com) and click Save.

GitHub will automatically create a CNAME file at the root of your published branch containing the domain you entered. Do not delete this file if you manage the site manually; otherwise the custom domain setting will be lost on the next push.

Step 3 — Enable HTTPS

After saving the custom domain, GitHub verifies that the DNS records point correctly. Once validation passes — usually within minutes, though it can take up to 24 hours — the Enforce HTTPS checkbox will become available. Enable it.

GitHub issues and renews the SSL certificate through Let's Encrypt at no extra cost. If the checkbox is greyed out or shows an error, DNS propagation probably hasn't finished yet. Wait an hour and reload the Settings page.

Common errors and how to fix them

  • "Domain is improperly configured": DNS records haven't propagated yet or point to the wrong value. Verify with dig www.yourdomain.com that the CNAME resolves to yourusername.github.io.
  • The CNAME file disappears after each push: include the CNAME file in your repository (at the root of the published directory) with your domain as its only content, or re-enter the custom domain in Settings after each deploy. If you use GitHub Actions, add the file as a build artifact.
  • HTTPS won't activate: wait for full propagation. If it still doesn't work after 24 hours, remove the custom domain in Settings, wait a minute, and re-enter it.
  • Root domain and www redirect incorrectly: check Settings → Pages to see which domain is declared as primary. GitHub redirects the other one to whichever you declared.

Need help registering the right domain before you connect it? Browse our domains category for registrar guides and pricing comparisons.

User repository vs. project repository

GitHub Pages has two modes:

  • User/organization repository (yourusername.github.io): the site lives at the root. Your custom domain maps directly to the site.
  • Project repository (yourusername.github.io/my-project): the site has a sub-path. If you attach a custom domain to this repository, the domain points to that project's site root, not to the /my-project path.

The DNS setup is identical in both cases; the only difference is which repository has the domain declared in Settings.

Looking for a reliable registrar with competitive prices? The team at elenlace.com can help you pick and register the perfect domain for your project.

Key takeaways

  • Subdomain (www) → CNAME record pointing to yourusername.github.io.
  • Apex domain (@) → four A records with GitHub Pages' IP addresses.
  • Declare the domain in Settings → Pages → Custom domain so GitHub can validate it.
  • The CNAME file in your repo preserves the setting across deployments.
  • HTTPS is free and automatic once DNS propagates correctly.
  • Propagation can take anywhere from minutes to 24 hours; wait before troubleshooting.

Already have a domain and want expert help connecting it? Reach out to the team at elenlace.com — we'll get your GitHub Pages site live under your own domain in no time.

FAQ

Can I use a .mx or any other extension with GitHub Pages?

Yes. GitHub Pages accepts any valid domain regardless of extension: .com, .mx, .com.mx, .io, .dev, and so on. The configuration process is identical for all of them.

Is GitHub Pages free with a custom domain?

Yes. GitHub Pages is free for public repositories (and private ones on Pro accounts). The custom domain and HTTPS certificate don't cost anything on GitHub's side; you only pay the annual renewal fee for your domain at your registrar.

How long does it take for my site to appear under the custom domain?

It depends on DNS propagation. In most cases the site is accessible within an hour, but the standard allows up to 48 hours. HTTPS may take a bit longer because it requires certificate issuance after DNS validation.

Can I use a custom domain on GitHub Pages with an organization?

Yes. The process is exactly the same: create the your-organization.github.io repository, configure DNS at your registrar, and declare the domain in Settings → Pages of that repository. Organization pages work just like user pages.

Further reading

Other providers and guides worth comparing:

← All