How to Add an HTML File to GitHub Pages

Ann Jul 09, 2026

Embarking on your journey to host your HTML files on GitHub Pages? You're in the right place. GitHub Pages is an excellent platform to showcase your web projects, personal websites, or even share your code with the world. Let's dive into a step-by-step guide on how to add your HTML file to GitHub Pages.

Host a website in under 2 minutes (Github Pages)
Host a website in under 2 minutes (Github Pages)

Before we begin, ensure you have a GitHub account and a basic understanding of Git. If you're new to Git, don't worry; we'll keep it simple. Let's start by creating a repository for your HTML file.

Master Git: Adding Files to the Staging Area
Master Git: Adding Files to the Staging Area

Setting Up Your Repository

Your GitHub Pages site will be hosted from a repository. Let's create one specifically for your HTML file.

How to Host a Website for Free Using GitHub Pages
How to Host a Website for Free Using GitHub Pages

1. Log in to your GitHub account and click the '+' icon in the top-right corner. Select 'New repository'.

Naming Your Repository

How to add onlf part of the file to Git
How to add onlf part of the file to Git

Name your repository in the format 'yourusername.github.io', replacing 'yourusername' with your GitHub username. This is because GitHub Pages uses this convention to host your site.

For example, if your GitHub username is 'johndoe', your repository name should be 'johndoe.github.io'.

Initializing Your Repository

the ultimate guide to creating and formating tags
the ultimate guide to creating and formating tags

After creating the repository, GitHub will take you to its main page. Here, click on the green 'Create new file' button. Name this file 'index.html'. This is the main file GitHub Pages will look for when displaying your site.

For now, leave the file empty. We'll add our HTML content later.

Creating Your HTML File

a screen shot of a web page with the words'html input types '
a screen shot of a web page with the words'html input types '

Now, let's create the HTML file you want to host on GitHub Pages.

1. On your local machine, create a new folder for your project. Inside this folder, create a new file and name it 'index.html'.

Basics of HTML
Basics of HTML
HTML Cheat Sheet πŸ“„βœ¨ Quick Guide for Beginners
HTML Cheat Sheet πŸ“„βœ¨ Quick Guide for Beginners
π™ƒπ™π™ˆπ™‡ π™π™–π™œπ™¨ π™˜π™π™šπ™–π™© π™¨π™π™šπ™šπ™©
π™ƒπ™π™ˆπ™‡ π™π™–π™œπ™¨ π™˜π™π™šπ™–π™© π™¨π™π™šπ™šπ™©
an image of the back side of a computer screen with text that reads, add css to html
an image of the back side of a computer screen with text that reads, add css to html
a computer screen with the text html and an image of a web page on it
a computer screen with the text html and an image of a web page on it
the github chat sheet is displayed in this screenshote screen graber
the github chat sheet is displayed in this screenshote screen graber
Add CSS In HTML
Add CSS In HTML
Embedding Images in HTML using <img>
Embedding Images in HTML using <img>
Git and GitHub Commands PDF - Complete Guide for Beginners to ProπŸš€πŸ’»  #git #command #code
Git and GitHub Commands PDF - Complete Guide for Beginners to ProπŸš€πŸ’» #git #command #code
Github Cheatsheet
Github Cheatsheet
Top 5 HTML CSS Projects for Beginners
Top 5 HTML CSS Projects for Beginners
4 Ways To Add Icons In HTML & CSS
4 Ways To Add Icons In HTML & CSS
a red and black text description for a web page with an arrow pointing to it
a red and black text description for a web page with an arrow pointing to it
an image of a web page with the text'html inputt types '
an image of a web page with the text'html inputt types '
🎨 3 Ways to Add CSS | Inline, Internal & External CSS Explained
🎨 3 Ways to Add CSS | Inline, Internal & External CSS Explained
login form html css
login form html css
How To Build A Tribute Page (freeCodeCamp Challenge)
How To Build A Tribute Page (freeCodeCamp Challenge)
#7:How to use .gitignore file | How to Create .gitignore file | How to add files to gitignore
#7:How to use .gitignore file | How to Create .gitignore file | How to add files to gitignore
Level Up Your Coding with GitHub: A Beginner's Guide
Level Up Your Coding with GitHub: A Beginner's Guide

Crafting Your HTML Content

Open this 'index.html' file in your preferred text editor or IDE and add your HTML content. Remember to keep the file structure simple for now. You can always add more files and complexity later.

Here's a simple HTML structure to get you started:

```html My GitHub Pages Site

Welcome to my GitHub Pages site!

This is a simple HTML file hosted on GitHub Pages.

```

Saving Your HTML File

Once you've added your content, save the file. Make sure to save it in the project folder you created earlier.

Now, let's push this file to your GitHub repository.

Pushing Your HTML File to GitHub

To push your local HTML file to your GitHub repository, you'll need to initialize a local Git repository, add your file, commit the changes, and then push to the remote repository.

Initializing Git

1. Open your terminal or command prompt, navigate to your project folder, and initialize a new Git repository with the command 'git init'.

2. Add your 'index.html' file to the Git repository with the command 'git add index.html'.

Committing Your Changes

1. Commit your changes with a meaningful commit message. For example, 'Initial commit of index.html'. Use the command 'git commit -m "Your commit message"'.

2. Now, connect your local repository to your GitHub repository. Use the command 'git remote add origin https://github.com/yourusername/yourusername.github.io.git', replacing 'yourusername' with your GitHub username.

Pushing Your HTML File to GitHub

Finally, push your changes to GitHub with the command 'git push -u origin main'. This will push your 'index.html' file to your GitHub repository.

After a few moments, your HTML file should be live on GitHub Pages. You can view it by navigating to 'https://yourusername.github.io', replacing 'yourusername' with your GitHub username.

Congratulations! You've successfully added your HTML file to GitHub Pages. Now, you can start building and expanding your site. Happy coding!