58

I am trying to add an image to the README.md in my repository using markdown below:

![ScreenShot](https://github.com/i-saumitra/Voice-controlled-MP3-Player/blob/master/screenshot.jpg)

But the image is not showing when I visit my repository. Instead the link to the image is showing up. Clicking the link will open the image in new window.

I have also tried using relative path:

![ScreenShot](screenshot.jpg)

But this is giving page not found error.

What is the correct markdown to display image in README.md

Both README.md and image file are in same path/directory.

What is the correct way to display an image in github README.md?

Complete content of README.md file is as below:

Voice-controlled-MP3-Player
===========================

A MP3 player which accept voice command like PLAY, PAUSE, FORWARD, etc. Using C# and Microsoft Speech API.

![ScreenShot](https://github.com/i-saumitra/Voice-controlled-MP3-Player/blob/master/screenshot.jpg)
Brad
  • 146,404
  • 44
  • 300
  • 476
AnonGeek
  • 6,820
  • 7
  • 35
  • 52
  • Possible duplicate of [Add images to README.md on GitHub](http://stackoverflow.com/questions/14494747/add-images-to-readme-md-on-github) – ashokramcse Nov 09 '16 at 07:01

9 Answers9

81

Updated content

Since January, 30th 2013, GitHub now supports relative links in markup documents.

This means that your code ![ScreenShot](screenshot.jpg) would now work flawlessly.

As pointed by @Brad, this may also ease a scenario where the images are different in two branches, but bear the same. In that case, switching from one branch to another, would dynamically switch the image in the rendered view, thus without requiring any change to the Readme content.

Previous answer when GitHub wasn't supporting relative links

You have to use the raw url format. In your case that would be https://raw.githubusercontent.com/i-saumitra/Voice-controlled-MP3-Player/master/screenshot.jpg

This means that the correct markdown would be the following

![ScreenShot](https://raw.githubusercontent.com/i-saumitra/Voice-controlled-MP3-Player/master/screenshot.jpg)

Using this in a .mdfile on github will display the following picture ;-)

ScreenShot

Update following your comment

where is this officialy documented that we have to use raw...i couldn't find it anywhere

This URL format is an undocumented feature of the GitHub site. This means that it could change later. If that ever happens, in order to "rediscover" the new format, click the Raw button when displaying a image. This will "open" the image in your browser. Copy the URL and Voilà!

raw

Note: Although the repository is no longer on hosted on GitHub, I've updated the urls to reflect the new GitHub policy regarding user content

nulltoken
  • 55,645
  • 19
  • 127
  • 125
  • thanks..works perfectly...btw where is this officialy documented that we have to use raw...i couldn't find it anywhere – AnonGeek Aug 11 '12 at 21:58
  • @Saumitra I've updated my answer. If this helped you, I wouldn't mind an upvote as well ;-) – nulltoken Aug 12 '12 at 08:21
  • 11
    For others finding this, Github now supports relative linkes: https://help.github.com/articles/relative-links-in-readmes – RyanJM Apr 10 '13 at 15:35
  • 1
    This is no longer a good solution. GitHub now supports linking to an image with a relative path: `![alt text](doc/image.png)` The benefit here is that you can use other branches and know that you have the right version of the images in your documentation. – Brad Jul 23 '14 at 16:47
  • @Brad: Thanks for reminding me of this. I've updated the answer accordingly. – nulltoken Jul 23 '14 at 18:14
  • @Brad I'm storing the images in an `assets` branch, and I'm having issues to make relative paths work with both the GitHub README, and with the README file locally. Please see [this question](https://stackoverflow.com/questions/49670565/display-github-readme-screenshot-stored-in-a-different-branch-both-on-github-an) – Alex Vang Apr 05 '18 at 13:39
36

You really should use relative urls. That way they'll work better for private repos as well.

![ScreenShot](/screenshots/latest.png)

supposing your repo has latest.png inside the screenshots folder.

~B

bosky101
  • 2,066
  • 1
  • 16
  • 10
  • 1
    I agree, preferably make it relative to an image within the repo :-) – Lee Englestone Jun 05 '14 at 08:10
  • 1
    It is especially true that Github occasionally change the raw file path, notably recently from "http://github.com/user-name/repo-name/raw/" to "https://raw.githubusercontent.com/user-name/repo-name/". Use relative paths so you don't need to check often if your repo image links are broken. – Yo Hsiao Jul 03 '14 at 22:04
  • You can also use `` If you want to support retina support by providing an image that is e.g. 200*200px ;) – electronix384128 Feb 06 '17 at 21:12
  • How can I display images from a private repo inside of the repo related public GitHub page? – Nicholas Allio Mar 10 '17 at 13:25
11

For relative URL's to work with images, wrap it inside the paragraph tag.

I was facing the problem, especially when working with the single image.

Example:

<p>
    <img src="relativePath/file.png" width="220" height="240" />
</p>
Rakesh Yembaram
  • 323
  • 3
  • 7
4

An extension to previous answers...

The image would not show for me when the line:

![ScreenShot](/image.png)

Was directly below a <h2></h2> line and I needed to add an empty line between them.

Hopefully this saves someone some time!

Josh Mitton
  • 101
  • 3
3

Thought I would update this for 2019 as I had trouble figuring this out for myself. I uploaded my images to a repo on GitHub, and then used the raw url of the image to import it into my markdown file. To get the raw url, click on the specific image link in GitHub so you are on the page for that specific image. To the top right of the photo, there are two buttons, "Download" and "History". If you click "Download", it takes you to that raw url with the picture taking up the full screen. Copy that url, and then paste it like this in your markdown file:

![image description or alt text](https://raw.githubusercontent.com/i-saumitra/Voice-controlled-MP3-Player/master/screenshot.jpg)

The button used to say "Raw" not "Download" so I hope this helps people find it.

Amanda
  • 31
  • 1
1

This may not be relevant to previous answers. I have the same question as the OP - I was directed here and it didnt help me. I hope I can help add light to this question however - as it covers the possibilities of why images does not render in README.md file.

The issue I encountered is that the file name README.md file is written as readME

Not only its missing .md its also written differently.

Apparently, we should not rename the README.md file. It has to be the original name of that file in order to render the images or gifs you want to upload on github README.md page. Hope this helps someone, in rare of occasions, just like I did.

Gel
  • 2,102
  • 1
  • 12
  • 23
0

Side note, when using reStructuredText use:

.. image:: /screenshots/latest.png?raw=true
brianray
  • 1,069
  • 1
  • 11
  • 15
0

I had to add a <br> to return a line in order for the image to show on mine. This discovery was inspired by the comment in this thread to leave a blank line after a tag.

Wai Ha Lee
  • 7,664
  • 52
  • 54
  • 80
MDShields
  • 47
  • 4
  • I'm new to this, would you care to explain the downvote? I can point you to a github repo I have which clearly shows that my comment is true. Although maybe you are saying my comment is not relevant enough? – MDShields Oct 01 '20 at 17:26
0

I've tested with "Copy path" and in some locations this was working and in others it didn't.

enter image description here

In the cases it didn't, I copied the permalink and used it instead.