What you'll end up with
By the end, your repository will have every photo stored in one img folder, your HTML will point to each photo with a short relative path, and each photo can be clicked to go to another page. Check off each step as you finish it. Your progress is saved in this browser.
my-repo/
├── index.html
├── golf.html
├── styles.css
└── img/
├── home.png
└── golf.png
-
1
Save each image as a
.pngor.jpg. If the images will sit side by side (like a menu), make them all the same width and height before you upload, so they line up.Keep the files small. A photo straight from a phone can be 5 MB or more and will load slowly. Around 100–300 KB is plenty for a web page. -
2
Rename the files before you upload them. Web servers are strict:
Home.pngandhome.pngare two different files.Good nameshome.pnggolf-course.jpgtennis_2.png
Names that break linksHome.png.png(two extensions)My Photo.PNG(spaces, capitals)golf(1).jpg(symbols)
Rules: all lowercase, no spaces (use
-or_), and exactly one extension.Seeing.png.png? Your computer hides extensions, so you typed.pngon top of one that was already there. On Windows turn on View → File name extensions; on a Mac use Finder → Settings → Advanced → Show all filename extensions. -
3
Go to
github.com/your-username/your-repoand make sure you're on themainbranch (the branch dropdown is at the top left of the file list). This is the branch GitHub Pages publishes. -
4
If an
imgfolder already exists, click it to go inside. If it doesn't, GitHub can't make an empty folder, so you create it while adding a file:- Click Add file → Create new file.
- In the name box type
img/. The slash turns it into a folder. - Type
.gitkeepas the file name, then click Commit changes.
Keeping every photo in oneimgfolder means every path in your HTML starts the same way:img/… -
5
While you're inside
img(the path at the top readsyour-repo / img), click Add file → Upload files, drag your photos in, write a short message likeAdd menu images, and click Commit changes.The most common mistake: uploading from the repo's main page. The photos then land next toindex.htmlinstead of inimg, andimg/golf.pngwon't find them. -
6
Open the
imgfolder and read each file name letter for letter. Whatever GitHub shows is what your HTML must say, including capital letters and the extension (.pngvs.jpgvs.jpeg).If a name is wrong, open the file, click the pencil (or …→ Rename), fix the name, and commit.
-
7
Open your HTML file on GitHub and click the pencil to edit. Add the image where you want it:
<img src="img/golf.png" alt="Golf">srcis the path from this HTML file to the photo: folder name, slash, file name.altdescribes the image for screen readers and shows if the image fails to load.
Use a relative pathimg/golf.png
AvoidC:\Users\me\Desktop\golf.png/Users/me/Pictures/golf.png
A path to your own computer works when you open the file locally, but nobody else has that file, so it breaks online. -
8
To make the photo clickable, put the
<img>inside an<a>tag. Thehrefis where the click goes:<a href="golf.html"> <img src="img/golf.png" alt="Golf"> </a>For a menu, repeat the pattern once per page and put them all inside a
<nav>:<nav> <a href="index.html"><img src="img/home.png" alt="Home"></a> <a href="golf.html"><img src="img/golf.png" alt="Golf"></a> </nav>Linking to another website? Use the full address:<a href="https://example.com">. Withouthttps://the browser looks for a file in your repo instead. -
9
Before you commit, go through each
srcandhrefand check it against the file list from step 6:- Same capital and lowercase letters
- Same extension (
.pngisn't.PNGor.jpg) - Folder name included (
img/) - Quotes closed and
</a>present
-
10
Scroll to Commit changes, write a message that says what you did (e.g.
Link menu images on home page), make sure Commit directly to the main branch is selected, and commit.If you used the same menu on several pages, repeat steps 7–10 for each page so they all match.
-
11
Open
https://your-username.github.io/your-repo/. GitHub needs about a minute to publish; you can watch it under the repo's Actions tab.- Every photo shows (no broken-image icon).
- Every photo-link opens the right page.
- Still seeing the old version? Hard refresh: Ctrl+Shift+R (Windows) or Cmd+Shift+R (Mac).
Quick test: right-click a broken image and choose Open image in new tab. The address bar shows the exact path the browser tried, so you can see what's misspelled. -
12
Delete any photos that ended up in the wrong place or with a bad name (for example a
golf.png.pngsitting next toindex.htmlwhen the real one isimg/golf.png). Open the file, click … → Delete file, and commit.Then reload your live site once more to confirm nothing you still use was removed.
Broken image? Find the cause
| What you see | Likely cause | Fix |
|---|---|---|
| Broken-image icon or just the alt text | The path doesn't match the file name or folder | Redo steps 6 and 9 |
| Works on your computer, broken online | A capital letter differs, or the path points to your computer | Make names lowercase, use img/… |
| Image shows but clicking does nothing | The <img> isn't inside <a>, or href is missing | Redo step 8 |
| Click goes to a 404 page | The href file name is misspelled | Match it to the HTML file name exactly |
| Change doesn't appear at all | Not committed to main, or the page is cached | Check the branch, wait a minute, hard refresh |