Learn how to host your website or project documentation directly from a GitHub repository using GitHub Pages.
- 1. What is GitHub Pages?
- 2. Types of GitHub Pages
- 3. Setting Up GitHub Pages
- 4. Custom Domain (Optional)
- 5. Tips and Notes
GitHub Pages is a free static site hosting service that takes files from a GitHub repository and serves them as a website.
Great for:
- Portfolios
- Project documentation
- Blog/static websites (Jekyll, Hugo, etc.)
-
User/Organization Site:
- Must be named
username.github.io - One per GitHub account
- Hosted from the root of the
mainbranch
- Must be named
-
Project Site:
- Can be any repo name
- Hosted from the
docs/folder orgh-pagesbranch - URL:
https://username.github.io/repository-name/
-
Go to your repository on GitHub.
-
Click on Settings > Pages (on the sidebar).
-
Under Source, choose:
- Branch:
main - Folder:
/rootor/docs(if your HTML is inside a docs folder)
- Branch:
-
Click Save.
-
GitHub will provide a URL to access your site.
index.html
style.cssOnce enabled, site will be hosted at:
https://username.github.io/repository-name/
- Purchase and configure your custom domain with DNS.
- In Pages settings, enter your custom domain.
- Create a
CNAMEfile with your domain name inside the repository (optional if GitHub adds it automatically). - GitHub handles HTTPS automatically.
- Changes pushed to the repo take a few seconds to reflect.
- Make sure your
index.htmlis at the correct location. - You can use GitHub Actions to automate build and deploy workflows.
- You can add
.nojekyllfile if you're not using Jekyll to avoid unwanted processing.
GitHub Pages is a powerful and free way to showcase your work or build lightweight web apps. Experiment with it and use it to give your projects a home online.
~Created by Piyush