Tuesday, May 21, 2024
For men, women, and teens

How to publish and display an html page on GitHub pages (illustrated)

Pinterest share Tumblr share

Written by Vera C. Last updated on .

Screenshot of how to setup GitHub pages - a tutorial for how to use GitHub pages

If you have an html page (or multiple pages) that you want to display as a functional web page on GitHub, this can be done. And yes, you can do it point and click, you don't need to use the command line to set this up. Here is a step-by-step illustrated tutorial for displaying an html page on GitHub.

Typical use cases for publishing an html page on GitHub

The most common use cases why you'd want to do this are:

  1. Your repository is a functional html page itself and you want to display it (for example, you've created a landing page). You want to show users how it looks at a glance in just one click. Or
  2. Example output is generated from your repository that you want to display (for example, you've created a program for generative fiction whose output is in html format). You want to show users example output.

In both cases, you want users to see the html page displayed as a functional page on GitHub pages in just 1 click, without them having to leave GitHub or download your repository first. You want to make it easy for users to see what they'd be getting.

There are other use cases for publishing html on GitHub, but the above two are the most common. And the good news is, GitHub pages is free! Let's move on and show you how to do it point and click, but first I'll cover a few restrictions you should be aware of.

Restrictions on publishing html pages on GitHub

There are a few restrictions; most are obvious and common-sense.

  • You can only publish static html sites on GitHub. You cannot use php or databases when publishing html pages on GitHub
  • Your content has to stay within the terms of service of GitHub i.e. no sexual or violent content, no get rich schemes, etc
  • GitHub is not allowed for commercial use. You're not allowed to use it as a free web hosting service to run your business or carry out commercial activity

For most people, these restrictions will not pose any problems.

1. Log into GitHub, go to your repository that contains your html

After you log into GitHub.com, go to the repository that contains your html file. In the example below, you can see I called my repository test-html.

Screenshot of a GitHub repository containing an html file and other files

Make sure your html file is called index.html - if not, change its name to index.html. In the image above, you can see it is called test.html so change it to index.html.

Then click on Settings, as shown circled in red towards the top right.

2. After Settings, look for Pages

So after step 1, your screen will look like this.

Screenshot of the repository settings in GitHub

Look for Pages in the menu on the left (circled in red in the image above) and click on that.

3. After Pages, select the branch of your repository (typically main)

After the previous step, your screen will look like this:

Screenshot of the GitHub Pages screen of a repository, showing the branch selection option

Under "Branch", choose the branch of your repository that you want to use the html from, as circled in the image above. This branch will typically be "main" unless you're doing something more complicated. After making the selection, you still have another step, so let's move on.

4. Specify the folder your html is in

At this point, you'll have your branch selected as in the image above. Now still need to tell GitHub where in your repository it's in. Unfortunately, GitHub only gives you 2 options: root or docs so you can't do anything more complicated than that. Most likely your html is in the root of your repository, as is the case for mine in the very first screenshot in step 1, so that's what I've selected here:

Screenshot of GitHub Pages in repository settings, showing folder selection option

Alternatively, you can opt to create a docs folder and put your html file in that, but I prefer not to unless I have a strong reason for doing so.

Then press Save, and you're done!

Finally! To view your published html page

To view your freshly published html page, navigate to the page using the following formula: https://yourgithubusername.github.io/repo-name

In other words, if your GitHub username is Acidity985 and the repository you used for this is called landing-page-test, then your github pages URL where you can view your site will be at https://acidity985.github.io/landing-page-test

Congratulations, you have created a page on GitHub pages.

Tips and tricks

  1. It always takes GitHub several minutes to update any changes you have made to your html page, including publishing it. So don't worry if you can't see the page right away, just wait and try again.
  2. Likewise, be aware of this delay when making changes to your html file - you'll need to wait awhile for any changes to go live. Yes, this is frustrating. Ideally you would make all your changes offline (on a copy of that file on your local computer) and later upload that file into your repository, replacing the old html file.
  3. You probably want to update your repository's README file to include a link to your published html page. Otherwise no-one else will ever know it's viewable as a published page.
  4. If you have placed or will place your html file in a docs folder instead of the root of your repository, remember to move over any other files needed also such as your css file, images, etc into the docs folder as well. If your GitHub pages CSS is not working, that is the first thing to check: that you have uploaded your stylesheet CSS file to the same repository AND that the location of the CSS relative to the index.html file remains the same. If it's not possible to keep the path the same, then you'll need to update the <head> section of the index.html file in your GitHub repository to reflect the new location of the CSS file in your repository.
  5. If your html page is not publishing, double-check the basics: your html file needs to be renamed to index.html, and wait a few minutes to be certain that the changes have had time to go live.

To unpublish your GitHub page

If you need to either temporarily or permanently unpublish your page from GitHub pages, then in the settings section of your GitHub repository (illustrated in Step 4), change the branch from "main" (or dev, or whatever), to "none". Then click "Save". Be patient - just as it took a few minutes to publish, it can also take a few minutes to unpublish.

Do you have more complex needs?

This article covered how to publish and display an html page on GitHub in the simplest possible way: manually via the graphical user interface. For the common simple use cases described here such as display of a landing page or of sample html output, this is the quick and easy way to do it via point and click.

However, if you have more complex requirements, here is additional information. For Jekyll users, you'll want to take a look at GitHub's guide to setting up a GitHub Pages site with Jekyll. If you're not planning on Jekyll but have other complex needs, GitHub has a separate guide on GitHub Pages and all its features. Additionally, GitHub Actions may be of interest to you.

Finally, if you're doing a lot of coding and need to concentrate, you should check out our playlist of instrumental music for focus and productivity.

Pinterest share Tumblr share

In: For menFor womentech

↑ top

Worldwide deals we recommend

Research your travel ideas for free with Tripadvisor

Tripadvisor is the best place for travel recommendations, hotel bookings, and everything else for your next trip.

Cool items from artisans near you

Put some brightness into your or someone else's day with a unique item from Etsy.com

Too busy to read? We recommend Audiobooks.com

Audiobooks.com has a huge selection of books you can listen to while you're running, sitting on the train, doing some home cleaning, or anytime. Put your earbuds in, relax and enjoy!