How to add images to README.md on GitHub?

GithubMarkdownGithub Flavored-MarkdownReadme

Github Problem Overview


Recently I joined GitHub. I hosted some projects there.

I need to include some images in my README File. I don't know how to do that.

I searched about this, but all I got was some links which tell me to "host images on web and specify the image path in README.md file".

Is there any way to do this without hosting the images on any third-party web hosting services?

Github Solutions


Solution 1 - Github

Try this markdown:

![alt text](http://url/to/img.png)

I think you can link directly to the raw version of an image if it's stored in your repository. i.e.

![alt text](https://github.com/[username]/[reponame]/blob/[branch]/image.jpg?raw=true)

Solution 2 - Github

You can also use relative paths like

![Alt text](relative/path/to/img.jpg?raw=true "Title")

Also try the following with the desired .fileExtention:

![plot](./directory_1/directory_2/.../directory_n/plot.png)

Solution 3 - Github

  • You can create a New Issue
  • upload(drag & drop) images to it
  • Copy the images URL and paste it into your README.md file.

here is a detailed youTube video explained this in detail:

https://www.youtube.com/watch?v=nvPOUdz5PL4

Solution 4 - Github

It's much simpler than that.

Just upload your image to the repository root, and link to the filename without any path, like so:

![Screenshot](screenshot.png)

Solution 5 - Github

You can also add images with simple HTML tags:

<p align="center">
  <img src="your_relative_path_here" width="350" title="hover text">
  <img src="your_relative_path_here_number_2_large_name" width="350" alt="accessibility text">
</p>

Solution 6 - Github

Many of the posted solutions are incomplete or not to my taste.

  • An external CDN like imgur adds another tool to the chain. Meh.
  • Creating a dummy issue in the issue tracker is a hack. It creates clutter and confuses users. It's a pain to migrate this solution to a fork, or off GitHub.
  • Using the gh-pages branch makes the URLs brittle. Another person working on the project maintaining the gh-page may not know something external depends on the path to these images. The gh-pages branch has a particular behavior on GitHub which is not necessary for hosting CDN images.
  • Tracking assets in version control is a good thing. As a project grows and changes it's a more sustainable way to manage and track changes by multiple users.
  • If an image applies to a specific revision of the software, it may be preferable to link an immutable image. That way, if the image is later updated to reflect changes to the software, anyone reading that revision's readme will find the correct image.

My preferred solution, inspired by this gist, is to use an assets branch with permalinks to specific revisions.

git checkout --orphan assets
git reset --hard
cp /path/to/cat.png .
git add .
git commit -m 'Added cat picture'
git push -u origin assets
git rev-parse HEAD  # Print the SHA, which is optional, you'll see below.

Construct a "permalink" to this revision of the image, and wrap it in Markdown. > Looking up the commit SHA by hand is inconvenient, however, so as a shortcut press Y to a permalink to a file in a specific commit as this help.github page says.

To always show the latest image on the assets branch, use the blob URL:

https://github.com/github/{repository}/blob/assets/cat.png 

(From the same GitHub help page File views show the latest version on a branch)

Solution 7 - Github

You can also insert [animated SVG images] in the markdown file like any other format.
It can be a good alternative to GIF images.

![image description](relative/path/in/repository/to/image.svg)
OR
<img src="relative/path/in/repository/to/image.svg" width="128"/>

Example (assuming the image is in assets directory in the repository):

![My animated logo](assets/my-logo.svg)

Result:

https://github.com/mahozad/mahozad/blob/master/logo.svg"> https://raw.githubusercontent.com/mahozad/mahozad/master/logo.svg" width="128"/>

[animated SVG images]: https://developer.mozilla.org/en-US/docs/Web/SVG/SVG_animation_with_SMIL "MDN Web Docs: SVG animation with SMIL"

Solution 8 - Github

Commit your image (image.png) in a folder (myFolder) and add the following line in your README.md:

![Optional Text](../master/myFolder/image.png)

Solution 9 - Github

> I need to include some images in my README File. I don't know how to > do that.

I created a small wizard that allows you to create and customize simple image galleries for your GitHub repository's readme: See ReadmeGalleryCreatorForGitHub.

The wizard takes advantage of the fact that GitHub allows img tags to occur in the README.md. Also, the wizard makes use of the popular trick of uploading images to GitHub by drag'n'dropping them in the issue area (as already mentioned in one of the answers in this thread).

enter image description here

Solution 10 - Github

  • Create an issue regarding adding images

  • Add the image by drag and drop or by file chooser

  • Then copy image source

  • Now add ![alt tag](http://url/to/img.png) to your README.md file

Done!

Alternatively you can use some image hosting site like imgur and get it's url and add it in your README.md file or you can use some static file hosting too.

Sample issue

Solution 11 - Github

Basic Syntax

![myimage-alt-tag](url-to-image)

Here:

  1. my-image-alt-tag : text that will be displayed if image is not shown.
  2. url-to-image : whatever your image resource is. URI of the image

Example:

![stack Overflow](http://lmsotfy.com/so.png)

This will look like the following:

stack overflow image by alamin

Solution 12 - Github

Very Simple : Can be done using Ctrl + C/V

Most of the answers here directly or indirectly involve uploading the image somewhere else & then providing a link to it.

It can be done very simply by just copying any image and pasting it while editing Readme.md

  • Copying the image - You can just click on the image file and use Ctrl + C or may copy the screenshot image to your clipboard using the snipping tool
  • You can then simply do Ctrl + V while editing Readme.md

Guithub will automatically upload it to user-images.githubusercontent.com and a link to it will be inserted there

Solution 13 - Github

Just add an <img> tag to your README.md with relative src to your repository. If you're not using relative src, make sure the server supports CORS.

It works because GitHub support inline-html

<img src="/docs/logo.png" alt="My cool logo"/>
# My cool project and above is the logo of it

Observe here

Solution 14 - Github

You can now drag and drop the images while editing the readme file.

Github will create a link for you which will be in the format of:

https://user-images.githubusercontent.com/******/********.file_format

Alternatively, at the bottom of the file, it says "Attach files by dragging & dropping, selecting or pasting them". If you click on that one, it will give you an option to upload a file directly or you can just paste it!

Solution 15 - Github

You Can use

![A test image](image.png)

Where ![A test image] is your alt text and (image.png) is the link to your image.


You can have the image on a cloud service or other online image hosting platforms Or you can provide the image link from the repository if it is in the repo


You can also make a specific folder inside your repository dedicated to your readme images

Solution 16 - Github

Step by step process, First create a folder ( name your folder ) and add the image/images that you want to upload in Readme.md file. ( you can also add the image/images in any existing folder of your project. ) Now,Click on edit icon of Readme.md file,then

![](relative url where images is located/refrence_image.png)  // refrence_image is the name of image in my case.

After adding image, you can see preview of changes in the, "Preview Changes" tab.you will find your image here. for example like this, In my case,

![](app/src/main/res/drawable/refrence_image.png)

app folder -> src folder -> main folder -> res folder -> drawable folder -> and inside drawable folder refrence_image.png file is located. For adding multiple images, you can do it like this,

![](app/src/main/res/drawable/refrence_image1.png)
![](app/src/main/res/drawable/refrence_image2.png)
![](app/src/main/res/drawable/refrence_image3.png)

Note 1 - Make sure your image file name does not contain any spaces. If it contain spaces then you need to add %20 for each space between the file name. It's better to remove the spaces.

Note 2 - you can even resize the image using HTML tags, or there are other ways. you can google it for more. if you need it.

After this, write your commit changes message, and then commit your Changes.

There are many other hacks of doing it like, create a issue and etc and etc. By far this is the best method that I have came across.

Solution 17 - Github

Use tables to stand out, it will give separate charm to it

Table Syntax is:

Separate each column cell by symbol |

and table header (First row) by 2nd row by ---


| col 1      | col 2      |

|------------|-------------|

| image 1 | image 2 |

output

enter image description here


Now just put <img src="url/relativePath"> at image 1 and image 2 if you are using two images


Note: if using multiple images just include more columns, you may use width and height attribute to make it look readable.

Example


| col 1      | col 2      |

|------------|-------------|

| <img src="https://media.wired.com/photos/5926db217034dc5f91becd6b/master/w_582,c_limit/so-logo-s.jpg" width="250"> | <img src="https://mk0jobadderjftub56m0.kinstacdn.com/wp-content/uploads/stackoverflow.com-300.jpg" width="250"> |

Spacing does not matter

Output image

enter image description here

helped by : adam-p

Solution 18 - Github

In new Github UI, this works for me -

Example - Commit your image.png in a folder (myFolder) and add the following line in your README.md:

![Optional Text](../main/myFolder/image.png)

Solution 19 - Github

You can just do:

git checkout --orphan assets
cp /where/image/currently/located/on/machine/diagram.png .
git add .
git commit -m 'Added diagram'
git push -u origin assets

Then you can just reference it in the README file like so:

![diagram](diagram.png)

Solution 20 - Github

JUST THIS WORKS!!

take care about your file name uppercase in tag and put PNG file inroot, and link to the filename without any path:

![Screenshot](screenshot.png)

Solution 21 - Github

I usually host the image on the site, this can link to any hosted image. Just toss this in the readme. Works for .rst files, not sure about .md

.. image:: https://url/path/to/image
   :height: 100px
   :width: 200 px
   :scale: 50 %

Solution 22 - Github

I have solved this problem. You only need to refer to someone else's readme file.

At first,you should upload an image file to github code library ! Then direct reference to the address of the image file .


https://github.com/mrhyh/TableView-/blob/master/%E8%AF%B4%E6%98%8E%E5%9B%BE/TableViewDemo.gif" />

enter image description here

enter image description here

Solution 23 - Github

In my case i use imgur and use the direct link this way.

![img](http://i.imgur.com/yourfilename.png)

Solution 24 - Github

You can link to images in your project from README.md (or externally) using the alternative github CDN link.

The URL will look like this:

https://cdn.rawgit.com/<USER>/<REPO>/<BRANCH>/<PATH>/<TO>/<FILE>

I have an SVG image in my project, and when I reference it in my Python project documentation, it does not render.

Here is the project link to the file (does not render as an image):

https://github.com/jongracecox/anybadge/blob/master/examples/awesomeness.svg

Example embedded image: image

Here is the RAW link to the file (still does not render as an image):

https://raw.githubusercontent.com/jongracecox/anybadge/master/examples/awesomeness.svg

Example embedded image: image

Using the CDN link, I can link to the file using (renders as an image):

https://cdn.rawgit.com/jongracecox/anybadge/master/examples/awesomeness.svg

Example embedded image: image

This is how I am able to use images from my project in both my README.md file, and in my PyPi project reStructredText doucmentation (here)

Solution 25 - Github

This Answer can also be found at: https://github.com/YourUserAccount/YourProject/blob/master/DirectoryPath/ReadMe.md

Display images from repo using:

prepend domain: https://raw.githubusercontent.com/
append flag: ?sanitize=true&raw=true
use <img /> tag
Eample url works for svg, png, and jpg using:
  • Domain: raw.githubusercontent.com/
  • UserName: YourUserAccount/
  • Repo: YourProject/
  • Branch: YourBranch/
  • Path: DirectoryPath/
  • Filename: example.png

Works for SVG, PNG, and JPEG

 - `raw.githubusercontent.com/YourUserAccount/YourProject/YourBranch/DirectoryPath/svgdemo1.svg?sanitize=true&raw=true`

Working example code displayed below after used:

**raw.githubusercontent.com**:
<img src="https://raw.githubusercontent.com/YourUserAccount/YourProject/master/DirectoryPath/Example.png?raw=true" />

<img src="https://raw.githubusercontent.com/YourUserAccount/YourProject/master/DirectoryPath/svgdemo1.svg?sanitize=true&raw=true" />

raw.githubusercontent.com:

https://raw.githubusercontent.com/YourUserAccount/YourProject/master/DirectoryPath/Example.png?raw=true" />

https://raw.githubusercontent.com/YourUserAccount/YourProject/master/DirectoryPath/svgdemo1.svg?sanitize=true&raw=true" />

Thanks:

Solution 26 - Github

There are 2 simple way you can do this ,

  1. use HTML img tag ,

  2. ![](the path where your image is saved/image-name.png)

the path would you can copy from the URL in the browser while you have opened that image. there might be an issue occur of spacing so make sure if there is any space b/w two words of path or in image name add-> %20. just like browser do.

Both of them will work , if you want to understand more you can check my github -> https://github.com/adityarawat29

Solution 27 - Github

I am just extending or adding an example to the already accepted answer.

Once you have put the image on your Github repo.

Then:

  • Open the corresponding Github repo on your browser.
  • Navigate to the target image file Then just open the image in a new tab. Opening the image in a new tab
  • Copy the url Copy the url from the browser tab
  • And finally insert the url to the following pattern ![alt text](https://raw.githubusercontent.com/username/projectname/branch/path/to/img.png)

On my case it is

![In a single picture](https://raw.githubusercontent.com/shadmazumder/Xcode/master/InOnePicture.png)

Where

  • shadmazumder is my username
  • Xcode is the projectname
  • master is the branch
  • InOnePicture.png is the image, On my case InOnePicture.png is in the root directory.

Solution 28 - Github

In my case I wanted to show a print screen on Github but also on NPM. Even though using the relative path was working within Github, it wasn't working outside of it. Basically, even if I pushed my project to NPM as well (which simply uses the same readme.md, the image was never showing.

I tried a few ways, at the end this is what worked for me:

![Preview](https://raw.githubusercontent.com/username/project/master/image-path/image.png)

I now see my image correctly on NPM or anywhere else that I could publish my package.

Solution 29 - Github

In case you need to upload some pictures for documentation, a nice approach is to use git-lfs. Asuming that you have installed the git-lfs follow these steps:

  1. Intialize git lfs for your each image type:

     git lfs *.png
     git lfs *.svg
     git lfs *.gif
     git lfs *.jpg
     git lfs *.jpeg
    
  2. Create a folder that will be used as image location eg. doc. On GNU/Linux and Unix based systems this can be done via:

     cd project_folder
     mkdir doc
     git add doc
    
  3. Copy paste any images into doc folder. Afterwards add them via git add command.

  4. Commit and push.

  5. The images are publicly available in the following url:

    https://media.githubusercontent.com/media/^github_username^/^repo^/^branch^/^image_location in the repo^

Where:

  • ^github_username^ is the username in github (you can find it in the profile page)
  • ^repo_name^ is the repository name
  • ^branch^ is the repository branch where the image is uploaded
  • ^image_location in the repo^ is the location including the folder that the image is stored.

Also you can upload the image first then visit the location in your projects github page and navigate through until you find the image then press the download button and then copy-paste the url from the browser's address bar.

Look this from my project as reference.

Then you can use the url to include them using the markdown syntax mentioned above:

![some alternate text that describes the image](^github generated url from git lfs^)

Eg: Let us suppose we use this photo Then you can use the markdown syntax:

![In what order to compile the files](https://media.githubusercontent.com/media/pc-magas/myFirstEnclave/master/doc/SGX%20Compile%20workflow.png)

Solution 30 - Github

I have found another solution but quite different and i'll explain it

Basically, i used the tag to show the image, but i wanted to go to another page when the image was clicked and here is how i did it.

<a href="the-url-you-want-to-go-when-image-is-clicked.com" />
<img src="image-source-url-location.com" />

If you put it right next to each other, separated by a new line, i guess when you click the image, it goes to the tag which has the href to the other site you want to redirect.

Solution 31 - Github

LATEST

> Wikis can display PNG, JPEG, or GIF images

Now you can use:

[[https://github.com/username/repository/blob/master/img/octocat.png|alt=octocat]]

-OR-

Follow these steps:

  1. On GitHub, navigate to the main page of the repository.

  2. Under your repository name, click Wiki.

  3. Using the wiki sidebar, navigate to the page you want to change, and then click Edit.

  4. On the wiki toolbar, click Image.

  5. In the "Insert Image" dialog box, type the image URL and the alt text (which is used by search engines and screen readers).

  6. Click OK.

Refer Docs.

Solution 32 - Github

Consider using a table if adding multiple screenshots and want to align them using tabular data for improved accessibility as shown here:

high-tea

If your markdown parser supports it you could also add the role="presentation" WIA-ARIA attribute to the TABLE element and omit the th tags.

Solution 33 - Github

Add image in your repository from upload file option then in README file

![Alt text]("enter repository image URL here") 

Solution 34 - Github

There's yet another option I haven't seen mentioned. You can simply create another repository under your user or organization called "assets". Push your images to this repo and reference them from your other repos:

![alt text](https://raw.githubusercontent.com/my-org/assets/master/folder/logo.png)

I've done this in one of my repos and it suits me fine. I can version my README images for all of my projects independently of my code, but still keep them all in one place. No issues or branches or other easily misplaced artifacts required.

Solution 35 - Github

We can do this simply,

  • create a New Issue on GitHub
  • drag and drop images on the body div of Issue

after a few seconds, a link will be generated. Now, copy the link or image URL and use it any supported platform.

Solution 36 - Github

For upload images with size managing option:

<img src="a.jpg" alt="J" width="200"/>

Solution 37 - Github

If you want to show an image hosted at any website (say url is "http:// abc.def.com/folder/image.jpg") then in your README.md file use the below syntax:

![alt text](<http:// abc.def.com/folder/image.jpg>)

  • Just browse to the image in your browser (may be by clicking on the image). It can be any website, including yours or somebody else's github hosted image.
  • Copy the url from the browser address bar, that is your "image_url" to be used in above referred syntax.

For images hosted in your own github repository you can use relative path in addition to the above url format
![alt text](<path_relative_to_current_github_location/image.jpg>)


If the image is located in the same folder as the README.md file (special case of relative path url), then you can use:
![alt text](<image.jpg>)

Note the angular brackets "<" and ">" enclosing the url. Sometimes these are required for the url to work.

Solution 38 - Github

If you dont't want to "mess up" your branch's content with these images and it's not a problem for you that the link is absolute, then I recommend to use a separate orphan branch to store these images. In this case, images will be integrated with the repo while not included in the main content. In addition, you can use LFS for larger files (all the leading git hosts support LFS).

You can easily create an orphan branch in the command line:

git checkout --orphan images
git reset --hard
cp /path/to/your/image.jpg ./image.jpg
git add --all
git commit -m "Add some images"
git checkout master
git log -n 3 --all --graph

If everyhing is OK, push the new branch:

git push -u origin images

Then use the raw github URL of the image.

Solution 39 - Github

You can as well drop the image at the appropriate part in the Read Me file.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMidhun MPView Question on Stackoverflow
Solution 1 - GithubcaptainclamView Answer on Stackoverflow
Solution 2 - GithubresultswayView Answer on Stackoverflow
Solution 3 - GithubAhmad AjmiView Answer on Stackoverflow
Solution 4 - Githubuser3638471View Answer on Stackoverflow
Solution 5 - GithubEvin1_View Answer on Stackoverflow
Solution 6 - GithubpaulmelnikowView Answer on Stackoverflow
Solution 7 - GithubMahozadView Answer on Stackoverflow
Solution 8 - GithubDarushView Answer on Stackoverflow
Solution 9 - GithubB12ToasterView Answer on Stackoverflow
Solution 10 - Githubabe312View Answer on Stackoverflow
Solution 11 - GithubalaminView Answer on Stackoverflow
Solution 12 - GithubAbdur RahmanView Answer on Stackoverflow
Solution 13 - GithubrocketspacerView Answer on Stackoverflow
Solution 14 - GithubsiamsotView Answer on Stackoverflow
Solution 15 - Githubkushagra-aaView Answer on Stackoverflow
Solution 16 - GithubJwala KumarView Answer on Stackoverflow
Solution 17 - GithubShashankesh UpadhyayView Answer on Stackoverflow
Solution 18 - GithubPrashant GaikwadView Answer on Stackoverflow
Solution 19 - GithubDanielView Answer on Stackoverflow
Solution 20 - GithubFarbod AprinView Answer on Stackoverflow
Solution 21 - GithubAdam HughesView Answer on Stackoverflow
Solution 22 - GithubylgwhyhView Answer on Stackoverflow
Solution 23 - GithubKegham K.View Answer on Stackoverflow
Solution 24 - GithubJGCView Answer on Stackoverflow
Solution 25 - GithubCrandellWSView Answer on Stackoverflow
Solution 26 - GithubAditya Singh RawatView Answer on Stackoverflow
Solution 27 - GithubShadView Answer on Stackoverflow
Solution 28 - GithubghiscodingView Answer on Stackoverflow
Solution 29 - GithubDimitrios DesyllasView Answer on Stackoverflow
Solution 30 - GithubLuisDev99View Answer on Stackoverflow
Solution 31 - GithubLal KrishnaView Answer on Stackoverflow
Solution 32 - GithubvhsView Answer on Stackoverflow
Solution 33 - GithubMarium JawedView Answer on Stackoverflow
Solution 34 - GithubJason DeMorrowView Answer on Stackoverflow
Solution 35 - GithubM.InnatView Answer on Stackoverflow
Solution 36 - Githubuser7551211View Answer on Stackoverflow
Solution 37 - GithubChinmayView Answer on Stackoverflow
Solution 38 - GithubDávid HorváthView Answer on Stackoverflow
Solution 39 - GithubDzhudView Answer on Stackoverflow