44

According to the GitHub documentation, the Markdown syntax for inserting an image is:

![GitHub Logo](/images/logo.png)
Format: ![Alt Text](url)

Following their example syntax, I can't seem to be able to make it work.

Even the GitHub logo example does not work.

What am I missing? Or is it a GitHub bug?

3
  • Change the URL to a full path complete with the HTTP and see where that takes you Aug 2, 2012 at 12:25
  • @EightDaysofMalaise: That does the trick indeed... Could you please write this as an answer? I reported the documentation error to Github.
    – nic
    Aug 3, 2012 at 1:49
  • I think their documentation changed. "Image", "picture" and "logo" are no longer mentioned on the page.
    – user72479
    Dec 30, 2015 at 20:15

4 Answers 4

36

You may be missing the full path/location to the image you want to include in your Markdown file.

The example given is a relative path, where the image rests on the same server as the file. In the help, it would assume the image is actually located at:

https://github.com/images/logo.png

But that is not a valid file or location.

In order to make sure you can render an image no matter where you're viewing it from, it's safer to include the full URL, which would include the domain name.

So your example would instead be using something similar to this:

![Bilby Stampede](http://example.com/images/logo.png)
26

In response to the answer above:

As of January 30th, 2013, GitHub now allow relative links.

Make sure that you append ?raw=true to the end of the URL, though. Here is an example:

![Image](../blob/master/public_html/img/nokia.png?raw=true)

Due to the way GitHub handles URL's, if you do not append ?raw=true to the source URL your browser will attempt to load the page which displays the image.

4
  • Are you sure that update also includes using as src? Jan 31, 2013 at 21:48
  • 1
    Yes, it does. Though, you have to append "?raw=true" to the end of the URL. Here's an example: ![Image](../blob/master/public_html/img/nokia.png?raw=true) Feb 1, 2013 at 6:29
  • Just updated the answer :). Feb 1, 2013 at 6:32
  • 1
    This works for my Markdown file but I get an error with pandoc: pandoc: Error producing PDF from TeX source. ! LaTeX Error: Unknown graphics extension: .png?raw=true. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ... l.175 ...2014-04-08_Bergman2011_Fig2.png?raw=true}
    – djhocking
    Apr 8, 2014 at 20:55
4

I like to test my Markdown locally before pushing somewhere viewable only through a URL. So I want a relative URL that I can use anywhere. GitHub now supports those.

Your images subdirectory, assuming it's in the same directory as your Markdown file, doesn't need a slash at the beginning — try:

markdown ![GitHub Logo](images/logo.png)

instead of

markdown ![GitHub Logo](/images/logo.png)

0

This is how it must be:

![Example image](./img/example.png)

The ./ tells GitHub to begin in the home directory of the repository. then you can add a / and after that the folder name and name of the image like the example I gave.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.