You built a personal portfolio, landing page, or frontend web project, and now you want to share a live URL with clients, friends, or hiring managers.
Instead of paying $5 to $15 a month for shared web hosting, GitHub Pages lets you host static websites (HTML, CSS, JavaScript, Astro, React, or Vue builds) 100% free forever directly from your GitHub repository.
In this tutorial, we cover how to publish your site to GitHub Pages in under 3 minutes, plus how to attach a custom domain.
Method 1: The Quick “main branch / root” Method (For Pure HTML/CSS/JS)
If your repository contains an index.html file right at the root:
- Open your repository on GitHub.com.
- Go to Settings (tab at the top right of your repository).
- In the left navigation sidebar under Code and automation, click Pages.
- Under Build and deployment → Source:
- Select Deploy from a branch.
- Branch: Select
main(ormaster). - Folder: Select
/ (root).
- Click Save.
Within 60 to 90 seconds, GitHub’s automated bot will build and publish your site at:
https://your-username.github.io/your-repository-name/
Method 2: Deploying from a Build Output Directory (e.g. dist or /docs)
If you use a build tool like Vite, Astro, or React:
Option A: The /docs Folder
- Configure your build tool to output to
docs/instead ofdist/(e.g., invite.config.js:build: { outDir: 'docs' }). - Run
npm run buildand push thedocs/folder to GitHub. - In Settings → Pages, choose branch:
mainand folder:/docs.
Option B: The gh-pages Branch (Automated)
Install the standard gh-pages utility:
npm install --save-dev gh-pages
Add deploy scripts to your package.json:
"scripts": {
"build": "vite build",
"deploy": "gh-pages -d dist"
}
Run:
npm run deploy
This automatically compiles your build and pushes the static assets to an isolated gh-pages branch. In Settings → Pages, simply select the gh-pages branch!
Step 3: Connecting a Custom Domain (e.g., yourname.com)
Want to use your own domain instead of github.io?
- In Settings → Pages, scroll to Custom domain.
- Type your domain (e.g.,
portfolio.yourbrand.comoryourbrand.com) and click Save. - In your DNS manager (Cloudflare, GoDaddy, Hostinger, Namecheap):
- For Subdomains (e.g.,
portfolio.brand.com): Add aCNAMErecord pointing toyour-username.github.io. - For Apex Domains (e.g.,
brand.com): Add 4Arecords pointing to GitHub’s IPs:185.199.108.153 185.199.109.153 185.199.110.153 185.199.111.153
- For Subdomains (e.g.,
- Back on GitHub Pages settings, check “Enforce HTTPS” to ensure automatic free SSL encryption.
Summary
GitHub Pages is the fastest, zero-cost method to get frontend code live on the web with enterprise-grade CDN distribution.
Need custom high-converting landing pages, Webflow builds, or bespoke web applications? Explore Klickspell’s services.