GitHub Pages
GitHub Pages: Free Static Hosting Directly from Git
GitHub Pages turns any public (or Team/Pro private) GitHub repository into a fast HTTPS static web host for HTML, CSS, JavaScript, and compiled frontend bundles. It is ideal for developer portfolios, project documentation, and live demos without renting a server.
Preparing Your Repository Files
GitHub Pages looks for an index.html entry file at the root of your chosen branch (or inside a /docs folder). Keep asset paths relative so styles and SVGs load cleanly whether your site is served at username.github.io/starter-site/ or a custom domain:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Starter Site</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h2>Starter Site</h2>
<object data="assets/banner.svg" type="image/svg+xml"></object>
</header>
</body>
</html>
Enabling GitHub Pages in Repository Settings
Push your index.html, styles.css, and assets/banner.svg files to main, then configure hosting in your browser:
- Open your repository on GitHub and click Settings.
- Select Pages in the left sidebar.
- Under Build and deployment > Source, pick Deploy from a branch (for plain HTML/CSS/JS) or GitHub Actions (for Vite, Next.js static export, or Astro).
- Choose branch
mainand folder/ (root), then click Save.
Within a minute or two, GitHub publishes your live URL at https://your-username.github.io/starter-site/ and enforces HTTPS automatically.
Using a Custom Domain
To serve your site at docs.yourdomain.com, enter your domain under Custom domain in Settings > Pages, then create a CNAME DNS record at your registrar pointing to your-username.github.io. GitHub commits a CNAME file to your branch and issues a free TLS certificate.
Common GitHub Pages Mistakes
Using leading-slash root paths like /styles.css fails when your project is hosted in a subpath like username.github.io/starter-site/. Use relative paths (styles.css or ./assets/banner.svg) or configure your bundler's base path.
Also remember GitHub Pages only hosts static files—server-side languages like PHP, Python Flask, or MySQL databases cannot execute on GitHub Pages.
Frequently Asked Questions
How long does a GitHub Pages update take after git push?
Usually 30 to 90 seconds. You can monitor the live deployment progress under the repository's Actions tab.
Can I publish a Next.js or React app to GitHub Pages?
Yes, if it builds to static HTML/CSS/JS files (such as output: 'export' in Next.js or vite build). Configure a GitHub Actions workflow to build and upload the out/ or dist/ directory.
Is GitHub Pages free for commercial or portfolio sites?
GitHub Pages is free for personal portfolios, open-source docs, and static demos within GitHub's published bandwidth and storage limits.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With