Linking Photos Correctly

A step-by-step guide to putting images into your GitHub repository and linking them from your HTML so they actually show up on your live site.

0 of 12 steps done
All 12 steps complete. Your photos are linked correctly!

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. 1

    Save each image as a .png or .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. 2

    Rename the files before you upload them. Web servers are strict: Home.png and home.png are two different files.

    Good names
    • home.png
    • golf-course.jpg
    • tennis_2.png
    Names that break links
    • Home.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 .png on 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. 3

    Go to github.com/your-username/your-repo and make sure you're on the main branch (the branch dropdown is at the top left of the file list). This is the branch GitHub Pages publishes.

  4. 4

    If an img folder 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 .gitkeep as the file name, then click Commit changes.
    Keeping every photo in one img folder means every path in your HTML starts the same way: img/…
  5. 5

    While you're inside img (the path at the top reads your-repo / img), click Add file → Upload files, drag your photos in, write a short message like Add menu images, and click Commit changes.

    The most common mistake: uploading from the repo's main page. The photos then land next to index.html instead of in img, and img/golf.png won't find them.
  6. 6

    Open the img folder and read each file name letter for letter. Whatever GitHub shows is what your HTML must say, including capital letters and the extension (.png vs .jpg vs .jpeg).

    If a name is wrong, open the file, click the pencil (or …→ Rename), fix the name, and commit.

  7. 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">
    • src is the path from this HTML file to the photo: folder name, slash, file name.
    • alt describes the image for screen readers and shows if the image fails to load.
    Use a relative path
    • img/golf.png
    Avoid
    • C:\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. 8

    To make the photo clickable, put the <img> inside an <a> tag. The href is 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">. Without https:// the browser looks for a file in your repo instead.
  9. 9

    Before you commit, go through each src and href and check it against the file list from step 6:

    • Same capital and lowercase letters
    • Same extension (.png isn't .PNG or .jpg)
    • Folder name included (img/)
    • Quotes closed and </a> present
  10. 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. 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. 12

    Delete any photos that ended up in the wrong place or with a bad name (for example a golf.png.png sitting next to index.html when the real one is img/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 seeLikely causeFix
Broken-image icon or just the alt textThe path doesn't match the file name or folderRedo steps 6 and 9
Works on your computer, broken onlineA capital letter differs, or the path points to your computerMake names lowercase, use img/…
Image shows but clicking does nothingThe <img> isn't inside <a>, or href is missingRedo step 8
Click goes to a 404 pageThe href file name is misspelledMatch it to the HTML file name exactly
Change doesn't appear at allNot committed to main, or the page is cachedCheck the branch, wait a minute, hard refresh